

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>cdt.causality &mdash; Causal Discovery Toolbox 0.5.22 documentation</title>
  

  
  <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="_static/custom.css" type="text/css" />

  
  
    <link rel="shortcut icon" href="_static/favicon.png"/>
  
  
  

  
  <!--[if lt IE 9]>
    <script src="_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
        <script src="_static/jquery.js"></script>
        <script src="_static/underscore.js"></script>
        <script src="_static/doctools.js"></script>
        <script src="_static/language_data.js"></script>
        <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
        <script type="text/x-mathjax-config">MathJax.Hub.Config({"extensions": ["tex2jax.js"], "jax": ["input/TeX", "output/HTML-CSS"], "tex2jax": {"inlineMath": [["$", "$"], ["\\(", "\\)"]], "displayMath": [["$$", "$$"], ["\\[", "\\]"]], "processEscapes": true}, "HTML-CSS": {"fonts": ["TeX"]}})</script>
    
    <script type="text/javascript" src="_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="cdt.independence" href="independence.html" />
    <link rel="prev" title="Advanced Tutorial" href="tutorial_2.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="index.html">
          

          
            
            <img src="_static/banner.png" class="logo" alt="Logo"/>
          
          </a>

          
            
            
              <div class="version">
                0.5.22
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul>
<li class="toctree-l1"><a class="reference internal" href="index.html">Causal Discovery Toolbox Documentation</a></li>
</ul>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="tutorial.html">Get started</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">cdt.causality</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#module-cdt.causality.pairwise">cdt.causality.pairwise</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#anm"><span class="hidden-section">ANM</span></a></li>
<li class="toctree-l3"><a class="reference internal" href="#bivariate-fit"><span class="hidden-section">Bivariate Fit</span></a></li>
<li class="toctree-l3"><a class="reference internal" href="#cds"><span class="hidden-section">CDS</span></a></li>
<li class="toctree-l3"><a class="reference internal" href="#gnn"><span class="hidden-section">GNN</span></a></li>
<li class="toctree-l3"><a class="reference internal" href="#igci"><span class="hidden-section">IGCI</span></a></li>
<li class="toctree-l3"><a class="reference internal" href="#jarfo"><span class="hidden-section">Jarfo</span></a></li>
<li class="toctree-l3"><a class="reference internal" href="#ncc"><span class="hidden-section">NCC</span></a></li>
<li class="toctree-l3"><a class="reference internal" href="#rcc"><span class="hidden-section">RCC</span></a></li>
<li class="toctree-l3"><a class="reference internal" href="#reci"><span class="hidden-section">RECI</span></a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#module-cdt.causality.graph">cdt.causality.graph</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#bnlearn-based-models"><span class="hidden-section">bnlearn-based models</span></a><ul>
<li class="toctree-l4"><a class="reference internal" href="#gs"><span class="hidden-section">GS</span></a></li>
<li class="toctree-l4"><a class="reference internal" href="#iamb"><span class="hidden-section">IAMB</span></a></li>
<li class="toctree-l4"><a class="reference internal" href="#fast-iamb"><span class="hidden-section">Fast_IAMB</span></a></li>
<li class="toctree-l4"><a class="reference internal" href="#inter-iamb"><span class="hidden-section">Inter_IAMB</span></a></li>
<li class="toctree-l4"><a class="reference internal" href="#mmpc"><span class="hidden-section">MMPC</span></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#cam"><span class="hidden-section">CAM</span></a></li>
<li class="toctree-l3"><a class="reference internal" href="#ccdr"><span class="hidden-section">CCDr</span></a></li>
<li class="toctree-l3"><a class="reference internal" href="#cgnn"><span class="hidden-section">CGNN</span></a></li>
<li class="toctree-l3"><a class="reference internal" href="#ges"><span class="hidden-section">GES</span></a></li>
<li class="toctree-l3"><a class="reference internal" href="#gies"><span class="hidden-section">GIES</span></a></li>
<li class="toctree-l3"><a class="reference internal" href="#lingam"><span class="hidden-section">LiNGAM</span></a></li>
<li class="toctree-l3"><a class="reference internal" href="#pc"><span class="hidden-section">PC</span></a></li>
<li class="toctree-l3"><a class="reference internal" href="#sam"><span class="hidden-section">SAM</span></a></li>
<li class="toctree-l3"><a class="reference internal" href="#samv1"><span class="hidden-section">SAMv1</span></a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="independence.html">cdt.independence</a></li>
<li class="toctree-l1"><a class="reference internal" href="data.html">cdt.data</a></li>
<li class="toctree-l1"><a class="reference internal" href="utils.html">cdt.utils</a></li>
<li class="toctree-l1"><a class="reference internal" href="metrics.html">cdt.metrics</a></li>
<li class="toctree-l1"><a class="reference internal" href="settings.html">Toolbox Settings</a></li>
<li class="toctree-l1"><a class="reference internal" href="models.html">PyTorch Models</a></li>
<li class="toctree-l1"><a class="reference internal" href="developer.html">Developer Documentation</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="index.html">Causal Discovery Toolbox</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="index.html" class="icon icon-home"></a> &raquo;</li>
        
      <li>cdt.causality</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="_sources/causality.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="cdt-causality">
<h1>cdt.causality<a class="headerlink" href="#cdt-causality" title="Permalink to this headline">¶</a></h1>
<div class="section" id="module-cdt.causality.pairwise">
<span id="cdt-causality-pairwise"></span><h2>cdt.causality.pairwise<a class="headerlink" href="#module-cdt.causality.pairwise" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt id="cdt.causality.pairwise.model.PairwiseModel">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.pairwise.model.</code><code class="sig-name descname">PairwiseModel</code><a class="reference internal" href="_modules/cdt/causality/pairwise/model.html#PairwiseModel"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.model.PairwiseModel" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for all pairwise causal inference models</p>
<p>Usage for undirected/directed graphs and CEPC df format.</p>
<dl class="py method">
<dt id="cdt.causality.pairwise.model.PairwiseModel.orient_graph">
<code class="sig-name descname">orient_graph</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">df_data</span></em>, <em class="sig-param"><span class="n">graph</span></em>, <em class="sig-param"><span class="n">printout</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/model.html#PairwiseModel.orient_graph"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.model.PairwiseModel.orient_graph" title="Permalink to this definition">¶</a></dt>
<dd><p>Orient an undirected graph using the pairwise method defined by the subclass.</p>
<p>The pairwise method is ran on every undirected edge.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>df_data</strong> (<em>pandas.DataFrame</em>) – Data</p></li>
<li><p><strong>graph</strong> (<em>networkx.Graph</em>) – Graph to orient</p></li>
<li><p><strong>printout</strong> (<em>str</em>) – (optional) Path to file where to save temporary results</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a directed graph, which might contain cycles</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Requirement : Name of the nodes in the graph correspond to name of
the variables in df_data</p>
</div>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.pairwise.model.PairwiseModel.predict">
<code class="sig-name descname">predict</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em>, <em class="sig-param"><span class="o">*</span><span class="n">args</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/model.html#PairwiseModel.predict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.model.PairwiseModel.predict" title="Permalink to this definition">¶</a></dt>
<dd><p>Generic predict method, chooses which subfunction to use for a more
suited.</p>
<p>Depending on the type of <cite>x</cite> and of <cite>*args</cite>, this function process to execute
different functions in the priority order:</p>
<ol class="arabic simple">
<li><p>If <code class="docutils literal notranslate"><span class="pre">args[0]</span></code> is a <code class="docutils literal notranslate"><span class="pre">networkx.(Di)Graph</span></code>, then <code class="docutils literal notranslate"><span class="pre">self.orient_graph</span></code> is executed.</p></li>
<li><p>If <code class="docutils literal notranslate"><span class="pre">args[0]</span></code> exists, then <code class="docutils literal notranslate"><span class="pre">self.predict_proba</span></code> is executed.</p></li>
<li><p>If <code class="docutils literal notranslate"><span class="pre">x</span></code> is a <code class="docutils literal notranslate"><span class="pre">pandas.DataFrame</span></code>, then <code class="docutils literal notranslate"><span class="pre">self.predict_dataset</span></code> is executed.</p></li>
<li><p>If <code class="docutils literal notranslate"><span class="pre">x</span></code> is a <code class="docutils literal notranslate"><span class="pre">pandas.Series</span></code>, then <code class="docutils literal notranslate"><span class="pre">self.predict_proba</span></code> is executed.</p></li>
</ol>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> (<em>numpy.array</em><em> or </em><em>pandas.DataFrame</em><em> or </em><em>pandas.Series</em>) – First variable or dataset.</p></li>
<li><p><strong>args</strong> (<em>numpy.array</em><em> or </em><em>networkx.Graph</em>) – graph or second variable.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>predictions output</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>pandas.Dataframe or networkx.Digraph</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.pairwise.model.PairwiseModel.predict_dataset">
<code class="sig-name descname">predict_dataset</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/model.html#PairwiseModel.predict_dataset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.model.PairwiseModel.predict_dataset" title="Permalink to this definition">¶</a></dt>
<dd><p>Generic dataset prediction function.</p>
<p>Runs the score independently on all pairs.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> (<em>pandas.DataFrame</em>) – a CEPC format Dataframe.</p></li>
<li><p><strong>kwargs</strong> (<em>dict</em>) – additional arguments for the algorithms</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a Dataframe with the predictions.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>pandas.DataFrame</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.pairwise.model.PairwiseModel.predict_proba">
<code class="sig-name descname">predict_proba</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">dataset</span></em>, <em class="sig-param"><span class="n">idx</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/model.html#PairwiseModel.predict_proba"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.model.PairwiseModel.predict_proba" title="Permalink to this definition">¶</a></dt>
<dd><p>Prediction method for pairwise causal inference.</p>
<p>predict_proba is meant to be overridden in all subclasses</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>dataset</strong> (<em>tuple</em>) – Couple of np.ndarray variables to classify</p></li>
<li><p><strong>idx</strong> (<em>int</em>) – (optional) index number for printing purposes</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Causation score (Value : 1 if a-&gt;b and -1 if b-&gt;a)</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>float</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

<div class="section" id="anm">
<h3><span class="hidden-section">ANM</span><a class="headerlink" href="#anm" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt id="cdt.causality.pairwise.ANM">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.pairwise.</code><code class="sig-name descname">ANM</code><a class="reference internal" href="_modules/cdt/causality/pairwise/ANM.html#ANM"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.ANM" title="Permalink to this definition">¶</a></dt>
<dd><p>ANM algorithm.</p>
<p><strong>Description</strong>: The Additive noise model is one of the most popular
approaches for pairwise causality. It bases on the fitness of the data to
the additive noise model on one direction and the rejection of the model
on the other direction.</p>
<p><strong>Data Type</strong>: Continuous</p>
<p><strong>Assumptions</strong>: Assuming that <span class="math notranslate nohighlight">\(x\rightarrow y\)</span> then we suppose that
the data follows an additive noise model, i.e. <span class="math notranslate nohighlight">\(y=f(x)+E\)</span>.
E being a noise variable and f a deterministic function.
The causal inference bases itself on the independence
between x and e.
It is proven that in such case if the data is generated using an additive noise model, the model would only be able
to fit in the true causal direction.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Ref : Hoyer, Patrik O and Janzing, Dominik and Mooij, Joris M and Peters, Jonas and Schölkopf, Bernhard,
“Nonlinear causal discovery with additive noise models”, NIPS 2009
<a class="reference external" href="https://papers.nips.cc/paper/3548-nonlinear-causal-discovery-with-additive-noise-models.pdf">https://papers.nips.cc/paper/3548-nonlinear-causal-discovery-with-additive-noise-models.pdf</a></p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.pairwise</span> <span class="kn">import</span> <span class="n">ANM</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">labels</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s1">&#39;tuebingen&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">ANM</span><span class="p">()</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># This example uses the predict() method</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># This example uses the orient_graph() method. The dataset used</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># can be loaded using the cdt.data module</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s1">&#39;sachs&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">orient_graph</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">nx</span><span class="o">.</span><span class="n">DiGraph</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># To view the directed graph run the following command</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<dl class="py method">
<dt id="cdt.causality.pairwise.ANM.anm_score">
<code class="sig-name descname">anm_score</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em>, <em class="sig-param"><span class="n">y</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/ANM.html#ANM.anm_score"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.ANM.anm_score" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute the fitness score of the ANM model in the x-&gt;y direction.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>a</strong> (<em>numpy.ndarray</em>) – Variable seen as cause</p></li>
<li><p><strong>b</strong> (<em>numpy.ndarray</em>) – Variable seen as effect</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>ANM fit score</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>float</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.pairwise.ANM.predict_proba">
<code class="sig-name descname">predict_proba</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/ANM.html#ANM.predict_proba"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.ANM.predict_proba" title="Permalink to this definition">¶</a></dt>
<dd><p>Prediction method for pairwise causal inference using the ANM model.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>dataset</strong> (<em>tuple</em>) – Couple of np.ndarray variables to classify</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Causation score (Value : 1 if a-&gt;b and -1 if b-&gt;a)</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>float</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="bivariate-fit">
<h3><span class="hidden-section">Bivariate Fit</span><a class="headerlink" href="#bivariate-fit" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt id="cdt.causality.pairwise.BivariateFit">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.pairwise.</code><code class="sig-name descname">BivariateFit</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ffactor</span><span class="o">=</span><span class="default_value">2</span></em>, <em class="sig-param"><span class="n">maxdev</span><span class="o">=</span><span class="default_value">3</span></em>, <em class="sig-param"><span class="n">minc</span><span class="o">=</span><span class="default_value">12</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/Bivariate_fit.html#BivariateFit"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.BivariateFit" title="Permalink to this definition">¶</a></dt>
<dd><p>Bivariate Fit model.</p>
<p><strong>Description:</strong> The bivariate fit model is  based onon a best-fit criterion
relying on a Gaussian Process regressor. Used as weak baseline.</p>
<p><strong>Data Type</strong>: Continuous</p>
<p><strong>Assumptions</strong>: This is often a model used to show that correlation
<span class="math notranslate nohighlight">\(\neq\)</span> causation. It holds very weak performance, as it states that
the best predictive model is the causal model.</p>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.pairwise</span> <span class="kn">import</span> <span class="n">BivariateFit</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">labels</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s1">&#39;tuebingen&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">BivariateFit</span><span class="p">()</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># This example uses the predict() method</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># This example uses the orient_graph() method. The dataset used</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># can be loaded using the cdt.data module</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">orient_graph</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#To view the directed graph run the following command</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<dl class="py method">
<dt id="cdt.causality.pairwise.BivariateFit.b_fit_score">
<code class="sig-name descname">b_fit_score</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em>, <em class="sig-param"><span class="n">y</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/Bivariate_fit.html#BivariateFit.b_fit_score"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.BivariateFit.b_fit_score" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the cds statistic from variable 1 to variable 2</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>a</strong> (<em>numpy.ndarray</em>) – Variable 1</p></li>
<li><p><strong>b</strong> (<em>numpy.ndarray</em>) – Variable 2</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>BF fit score</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>float</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.pairwise.BivariateFit.predict_proba">
<code class="sig-name descname">predict_proba</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">dataset</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/Bivariate_fit.html#BivariateFit.predict_proba"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.BivariateFit.predict_proba" title="Permalink to this definition">¶</a></dt>
<dd><p>Infer causal relationships between 2 variables using regression.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>dataset</strong> (<em>tuple</em>) – Couple of np.ndarray variables to classify</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Causation score (Value : 1 if a-&gt;b and -1 if b-&gt;a)</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>float</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="cds">
<h3><span class="hidden-section">CDS</span><a class="headerlink" href="#cds" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt id="cdt.causality.pairwise.CDS">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.pairwise.</code><code class="sig-name descname">CDS</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ffactor</span><span class="o">=</span><span class="default_value">2</span></em>, <em class="sig-param"><span class="n">maxdev</span><span class="o">=</span><span class="default_value">3</span></em>, <em class="sig-param"><span class="n">minc</span><span class="o">=</span><span class="default_value">12</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/CDS.html#CDS"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.CDS" title="Permalink to this definition">¶</a></dt>
<dd><p>Conditional Distribution Similarity Statistic</p>
<p><strong>Description:</strong> The Conditional Distribution Similarity Statistic measures the
std. of the rescaled values of y (resp. x) after binning in the x (resp. y) direction.
The lower the std. the more likely the pair to be x-&gt;y (resp. y-&gt;x). It is
a single feature of the Jarfo model.</p>
<p><strong>Data Type</strong>: Continuous and Discrete</p>
<p><strong>Assumptions</strong>: This approach is a statistical feature of the
joint distribution of the data mesuring the variance of the marginals, after
conditioning on bins.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Ref : Fonollosa, José AR, “Conditional distribution variability measures for causality detection”, 2016.</p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.pairwise</span> <span class="kn">import</span> <span class="n">CDS</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">labels</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s1">&#39;tuebingen&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">CDS</span><span class="p">()</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># This example uses the predict() method</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># This example uses the orient_graph() method. The dataset used</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># can be loaded using the cdt.data module</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">orient_graph</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#To view the directed graph run the following command</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<dl class="py method">
<dt id="cdt.causality.pairwise.CDS.cds_score">
<code class="sig-name descname">cds_score</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x_te</span></em>, <em class="sig-param"><span class="n">y_te</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/CDS.html#CDS.cds_score"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.CDS.cds_score" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the cds statistic from variable 1 to variable 2</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x_te</strong> (<em>numpy.ndarray</em>) – Variable 1</p></li>
<li><p><strong>y_te</strong> (<em>numpy.ndarray</em>) – Variable 2</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>CDS fit score</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>float</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.pairwise.CDS.predict_proba">
<code class="sig-name descname">predict_proba</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">dataset</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/CDS.html#CDS.predict_proba"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.CDS.predict_proba" title="Permalink to this definition">¶</a></dt>
<dd><p>Infer causal relationships between 2 variables using the CDS statistic</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>dataset</strong> (<em>tuple</em>) – Couple of np.ndarray variables to classify</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Causation score (Value : 1 if a-&gt;b and -1 if b-&gt;a)</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>float</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="gnn">
<h3><span class="hidden-section">GNN</span><a class="headerlink" href="#gnn" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt id="cdt.causality.pairwise.GNN">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.pairwise.</code><code class="sig-name descname">GNN</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">nh</span><span class="o">=</span><span class="default_value">20</span></em>, <em class="sig-param"><span class="n">lr</span><span class="o">=</span><span class="default_value">0.01</span></em>, <em class="sig-param"><span class="n">nruns</span><span class="o">=</span><span class="default_value">6</span></em>, <em class="sig-param"><span class="n">njobs</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">gpus</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">verbose</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">batch_size</span><span class="o">=</span><span class="default_value">- 1</span></em>, <em class="sig-param"><span class="n">train_epochs</span><span class="o">=</span><span class="default_value">1000</span></em>, <em class="sig-param"><span class="n">test_epochs</span><span class="o">=</span><span class="default_value">1000</span></em>, <em class="sig-param"><span class="n">dataloader_workers</span><span class="o">=</span><span class="default_value">0</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/GNN.html#GNN"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.GNN" title="Permalink to this definition">¶</a></dt>
<dd><p>Shallow Generative Neural networks.</p>
<p><strong>Description:</strong> Pairwise variant of the CGNN approach,
Models the causal directions x-&gt;y and y-&gt;x with a 1-hidden layer neural
network and a MMD loss. The causal direction is considered as the best-fit
between the two causal directions.</p>
<p><strong>Data Type:</strong> Continuous</p>
<p><strong>Assumptions:</strong> The class of generative models is not restricted with a
hard contraint, but with the hyperparameter <code class="docutils literal notranslate"><span class="pre">nh</span></code>. This algorithm greatly
benefits from bootstrapped runs (nruns &gt;=12 recommended), and is very
computationnally heavy. GPUs are recommended.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>nh</strong> (<em>int</em>) – number of hidden units in the neural network</p></li>
<li><p><strong>lr</strong> (<em>float</em>) – learning rate of the optimizer</p></li>
<li><p><strong>nruns</strong> (<em>int</em>) – number of runs to execute per batch
(before testing for significance with t-test).</p></li>
<li><p><strong>njobs</strong> (<em>int</em>) – number of runs to execute in parallel.
(defaults to <code class="docutils literal notranslate"><span class="pre">cdt.SETTINGS.NJOBS</span></code>)</p></li>
<li><p><strong>gpus</strong> (<em>bool</em>) – Number of available gpus
(defaults to <code class="docutils literal notranslate"><span class="pre">cdt.SETTINGS.GPU</span></code>)</p></li>
<li><p><strong>idx</strong> (<em>int</em>) – (optional) index of the pair, for printing purposes</p></li>
<li><p><strong>verbose</strong> (<em>bool</em>) – verbosity (defaults to <code class="docutils literal notranslate"><span class="pre">cdt.SETTINGS.verbose</span></code>)</p></li>
<li><p><strong>batch_size</strong> (<em>int</em>) – batch size, defaults to full-batch</p></li>
<li><p><strong>train_epochs</strong> (<em>int</em>) – Number of epochs used for training</p></li>
<li><p><strong>test_epochs</strong> (<em>int</em>) – Number of epochs used for evaluation</p></li>
<li><p><strong>dataloader_workers</strong> (<em>int</em>) – how many subprocesses to use for data
loading. 0 means that the data will be loaded in the main
process. (default: 0)</p></li>
</ul>
</dd>
</dl>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Ref : Learning Functional Causal Models with Generative Neural Networks
Olivier Goudet &amp; Diviyan Kalainathan &amp; Al.
(<a class="reference external" href="https://arxiv.org/abs/1709.05321">https://arxiv.org/abs/1709.05321</a>)</p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.pairwise</span> <span class="kn">import</span> <span class="n">GNN</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">labels</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s1">&#39;tuebingen&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">GNN</span><span class="p">()</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># This example uses the predict() method</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># This example uses the orient_graph() method. The dataset used</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># can be loaded using the cdt.data module</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">orient_graph</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#To view the directed graph run the following command</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<dl class="py method">
<dt id="cdt.causality.pairwise.GNN.orient_graph">
<code class="sig-name descname">orient_graph</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">df_data</span></em>, <em class="sig-param"><span class="n">graph</span></em>, <em class="sig-param"><span class="n">printout</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/GNN.html#GNN.orient_graph"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.GNN.orient_graph" title="Permalink to this definition">¶</a></dt>
<dd><p>Orient an undirected graph using the pairwise method defined by the subclass.</p>
<p>The pairwise method is ran on every undirected edge.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>df_data</strong> (<em>pandas.DataFrame</em><em> or </em><em>MetaDataset</em>) – Data (check cdt.utils.io.MetaDataset)</p></li>
<li><p><strong>graph</strong> (<em>networkx.Graph</em>) – Graph to orient</p></li>
<li><p><strong>printout</strong> (<em>str</em>) – (optional) Path to file where to save temporary results</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a directed graph, which might contain cycles</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>This function is an override of the base class, in order to be able
to use the torch.utils.data.Dataset classes</p>
</div>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Requirement : Name of the nodes in the graph correspond to name of
the variables in df_data</p>
</div>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.pairwise.GNN.predict_proba">
<code class="sig-name descname">predict_proba</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">dataset</span></em>, <em class="sig-param"><span class="n">idx</span><span class="o">=</span><span class="default_value">0</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/GNN.html#GNN.predict_proba"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.GNN.predict_proba" title="Permalink to this definition">¶</a></dt>
<dd><p>Run multiple times GNN to estimate the causal direction.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>dataset</strong> (<em>torch.utils.data.Dataset</em><em> or </em><em>tuple</em>) – pair (x, y) to
classify. Either a tuple or a torch dataset.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Causal score of the pair (Value : 1 if a-&gt;b and -1 if b-&gt;a)</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>float</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="igci">
<h3><span class="hidden-section">IGCI</span><a class="headerlink" href="#igci" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt id="cdt.causality.pairwise.IGCI">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.pairwise.</code><code class="sig-name descname">IGCI</code><a class="reference internal" href="_modules/cdt/causality/pairwise/IGCI.html#IGCI"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.IGCI" title="Permalink to this definition">¶</a></dt>
<dd><p>IGCI model.</p>
<p><strong>Description:</strong> Information Geometric Causal Inference is a pairwise causal
discovery model model considering the case of minimal noise <span class="math notranslate nohighlight">\(Y=f(X)\)</span>,
with <span class="math notranslate nohighlight">\(f\)</span> invertible and leverages assymetries to predict causal
directions.</p>
<p><strong>Data Type:</strong> Continuous</p>
<p><strong>Assumptions:</strong> Only the case of invertible functions only is considered, as the
prediction would be trivial otherwise if the noise is minimal.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>P. Daniušis, D. Janzing, J. Mooij, J. Zscheischler, B. Steudel,
K. Zhang, B. Schölkopf:  Inferring deterministic causal relations.
Proceedings of the 26th Annual Conference on Uncertainty in Artificial  Intelligence (UAI-2010).
<a class="reference external" href="http://event.cwi.nl/uai2010/papers/UAI2010_0121.pdf">http://event.cwi.nl/uai2010/papers/UAI2010_0121.pdf</a></p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.pairwise</span> <span class="kn">import</span> <span class="n">IGCI</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">labels</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s1">&#39;tuebingen&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">IGCI</span><span class="p">()</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># This example uses the predict() method</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># This example uses the orient_graph() method. The dataset used</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># can be loaded using the cdt.data module</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">orient_graph</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#To view the directed graph run the following command</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<dl class="py method">
<dt id="cdt.causality.pairwise.IGCI.predict_proba">
<code class="sig-name descname">predict_proba</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">dataset</span></em>, <em class="sig-param"><span class="n">ref_measure</span><span class="o">=</span><span class="default_value">'gaussian'</span></em>, <em class="sig-param"><span class="n">estimator</span><span class="o">=</span><span class="default_value">'entropy'</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/IGCI.html#IGCI.predict_proba"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.IGCI.predict_proba" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluate a pair using the IGCI model.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>dataset</strong> (<em>tuple</em>) – Couple of np.ndarray variables to classify</p></li>
<li><p><strong>refMeasure</strong> (<em>str</em>) – Scaling method (gaussian (default),
integral or None)</p></li>
<li><p><strong>estimator</strong> (<em>str</em>) – method used to evaluate the pairs (entropy (default)
or integral)}</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>value of the IGCI model &gt;0 if a-&gt;b otherwise if return &lt;0</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>float</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="jarfo">
<h3><span class="hidden-section">Jarfo</span><a class="headerlink" href="#jarfo" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt id="cdt.causality.pairwise.Jarfo">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.pairwise.</code><code class="sig-name descname">Jarfo</code><a class="reference internal" href="_modules/cdt/causality/pairwise/Jarfo.html#Jarfo"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.Jarfo" title="Permalink to this definition">¶</a></dt>
<dd><p>Jarfo model, 2nd of the Cause Effect Pairs challenge,
1st of the Fast Causation Challenge.</p>
<p><strong>Description:</strong> The Jarfo model is an ensemble method for causal discovery:
it builds lots of causally relevant features (such as ANM) with a
gradient boosting classifier on top.</p>
<p><strong>Data Type:</strong> Continuous, Categorical, Mixed</p>
<p><strong>Assumptions:</strong> This method needs a substantial amount of labelled causal
pairs to train itself. Its final performance depends on the training set
used.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Ref : Fonollosa, José AR, “Conditional distribution variability measures for causality detection”, 2016.</p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.pairwise</span> <span class="kn">import</span> <span class="n">Jarfo</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sklearn.model_selection</span> <span class="kn">import</span> <span class="n">train_test_split</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">labels</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s1">&#39;tuebingen&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X_tr</span><span class="p">,</span> <span class="n">X_te</span><span class="p">,</span> <span class="n">y_tr</span><span class="p">,</span> <span class="n">y_te</span> <span class="o">=</span> <span class="n">train_test_split</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">labels</span><span class="p">,</span> <span class="n">train_size</span><span class="o">=.</span><span class="mi">5</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">Jarfo</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">X_tr</span><span class="p">,</span> <span class="n">y_tr</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># This example uses the predict() method</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">X_te</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># This example uses the orient_graph() method. The dataset used</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># can be loaded using the cdt.data module</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">orient_graph</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#To view the directed graph run the following command</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<dl class="py method">
<dt id="cdt.causality.pairwise.Jarfo.orient_graph">
<code class="sig-name descname">orient_graph</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">df_data</span></em>, <em class="sig-param"><span class="n">graph</span></em>, <em class="sig-param"><span class="n">printout</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/Jarfo.html#Jarfo.orient_graph"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.Jarfo.orient_graph" title="Permalink to this definition">¶</a></dt>
<dd><p>Orient an undirected graph using Jarfo, function modified for optimization.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>df_data</strong> (<em>pandas.DataFrame</em>) – Data</p></li>
<li><p><strong>umg</strong> (<em>networkx.Graph</em>) – Graph to orient</p></li>
<li><p><strong>nruns</strong> (<em>int</em>) – number of times to rerun for each pair (bootstrap)</p></li>
<li><p><strong>printout</strong> (<em>str</em>) – (optional) Path to file where to save temporary results</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a directed graph, which might contain cycles</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.pairwise.Jarfo.predict_dataset">
<code class="sig-name descname">predict_dataset</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">df</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/Jarfo.html#Jarfo.predict_dataset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.Jarfo.predict_dataset" title="Permalink to this definition">¶</a></dt>
<dd><p>Runs Jarfo independently on all pairs.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> (<em>pandas.DataFrame</em>) – a CEPC format Dataframe.</p></li>
<li><p><strong>kwargs</strong> (<em>dict</em>) – additional arguments for the algorithms</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a Dataframe with the predictions.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>pandas.DataFrame</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.pairwise.Jarfo.predict_proba">
<code class="sig-name descname">predict_proba</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">dataset</span></em>, <em class="sig-param"><span class="n">idx</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/Jarfo.html#Jarfo.predict_proba"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.Jarfo.predict_proba" title="Permalink to this definition">¶</a></dt>
<dd><p>Use Jarfo to predict the causal direction of a pair of vars.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>dataset</strong> (<em>tuple</em>) – Couple of np.ndarray variables to classify</p></li>
<li><p><strong>idx</strong> (<em>int</em>) – (optional) index number for printing purposes</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Causation score (Value : 1 if a-&gt;b and -1 if b-&gt;a)</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>float</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="ncc">
<h3><span class="hidden-section">NCC</span><a class="headerlink" href="#ncc" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt id="cdt.causality.pairwise.NCC">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.pairwise.</code><code class="sig-name descname">NCC</code><a class="reference internal" href="_modules/cdt/causality/pairwise/NCC.html#NCC"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.NCC" title="Permalink to this definition">¶</a></dt>
<dd><p>Neural Causation Coefficient.</p>
<p><strong>Description:</strong> The Neural Causation Coefficient (NCC) is an approach
neural network relying only on Neural networks to build causally relevant
embeddings of distributions during training, and classyfing the pairs using
the last layers of the neural network.</p>
<p><strong>Data Type:</strong> Continuous, Categorical, Mixed</p>
<p><strong>Assumptions:</strong> This method needs a substantial amount of labelled causal
pairs to train itself. Its final performance depends on the training set
used.</p>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.pairwise</span> <span class="kn">import</span> <span class="n">NCC</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sklearn.model_selection</span> <span class="kn">import</span> <span class="n">train_test_split</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">labels</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s1">&#39;tuebingen&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X_tr</span><span class="p">,</span> <span class="n">X_te</span><span class="p">,</span> <span class="n">y_tr</span><span class="p">,</span> <span class="n">y_te</span> <span class="o">=</span> <span class="n">train_test_split</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">labels</span><span class="p">,</span> <span class="n">train_size</span><span class="o">=.</span><span class="mi">5</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">NCC</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">X_tr</span><span class="p">,</span> <span class="n">y_tr</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># This example uses the predict() method</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">X_te</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># This example uses the orient_graph() method. The dataset used</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># can be loaded using the cdt.data module</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">orient_graph</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#To view the directed graph run the following command</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<dl class="py method">
<dt id="cdt.causality.pairwise.NCC.fit">
<code class="sig-name descname">fit</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x_tr</span></em>, <em class="sig-param"><span class="n">y_tr</span></em>, <em class="sig-param"><span class="n">epochs</span><span class="o">=</span><span class="default_value">50</span></em>, <em class="sig-param"><span class="n">batch_size</span><span class="o">=</span><span class="default_value">32</span></em>, <em class="sig-param"><span class="n">learning_rate</span><span class="o">=</span><span class="default_value">0.01</span></em>, <em class="sig-param"><span class="n">verbose</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">device</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/NCC.html#NCC.fit"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.NCC.fit" title="Permalink to this definition">¶</a></dt>
<dd><p>Fit the NCC model.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x_tr</strong> (<em>pd.DataFrame</em>) – CEPC format dataframe containing the pairs</p></li>
<li><p><strong>y_tr</strong> (<em>pd.DataFrame</em><em> or </em><em>np.ndarray</em>) – labels associated to the pairs</p></li>
<li><p><strong>epochs</strong> (<em>int</em>) – number of train epochs</p></li>
<li><p><strong>learning_rate</strong> (<em>float</em>) – learning rate of Adam</p></li>
<li><p><strong>verbose</strong> (<em>bool</em>) – verbosity (defaults to <code class="docutils literal notranslate"><span class="pre">cdt.SETTINGS.verbose</span></code>)</p></li>
<li><p><strong>device</strong> (<em>str</em>) – cuda or cpu device (defaults to <code class="docutils literal notranslate"><span class="pre">cdt.SETTINGS.default_device</span></code>)</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.pairwise.NCC.predict_dataset">
<code class="sig-name descname">predict_dataset</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">df</span></em>, <em class="sig-param"><span class="n">device</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">verbose</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/NCC.html#NCC.predict_dataset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.NCC.predict_dataset" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x_tr</strong> (<em>pd.DataFrame</em>) – CEPC format dataframe containing the pairs</p></li>
<li><p><strong>epochs</strong> (<em>int</em>) – number of train epochs</p></li>
<li><p><strong>rate</strong> (<em>learning</em>) – learning rate of Adam</p></li>
<li><p><strong>verbose</strong> (<em>bool</em>) – verbosity (defaults to <code class="docutils literal notranslate"><span class="pre">cdt.SETTINGS.verbose</span></code>)</p></li>
<li><p><strong>device</strong> (<em>str</em>) – cuda or cpu device (defaults to <code class="docutils literal notranslate"><span class="pre">cdt.SETTINGS.default_device</span></code>)</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>dataframe containing the predicted causation coefficients</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>pandas.DataFrame</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.pairwise.NCC.predict_proba">
<code class="sig-name descname">predict_proba</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">dataset</span></em>, <em class="sig-param"><span class="n">device</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">idx</span><span class="o">=</span><span class="default_value">0</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/NCC.html#NCC.predict_proba"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.NCC.predict_proba" title="Permalink to this definition">¶</a></dt>
<dd><p>Infer causal directions using the trained NCC pairwise model.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>dataset</strong> (<em>tuple</em>) – Couple of np.ndarray variables to classify</p></li>
<li><p><strong>device</strong> (<em>str</em>) – Device to run the algorithm on (defaults to <code class="docutils literal notranslate"><span class="pre">cdt.SETTINGS.default_device</span></code>)</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Causation score (Value : 1 if a-&gt;b and -1 if b-&gt;a)</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>float</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="rcc">
<h3><span class="hidden-section">RCC</span><a class="headerlink" href="#rcc" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt id="cdt.causality.pairwise.RCC">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.pairwise.</code><code class="sig-name descname">RCC</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">rand_coeff</span><span class="o">=</span><span class="default_value">333</span></em>, <em class="sig-param"><span class="n">nb_estimators</span><span class="o">=</span><span class="default_value">500</span></em>, <em class="sig-param"><span class="n">nb_min_leaves</span><span class="o">=</span><span class="default_value">20</span></em>, <em class="sig-param"><span class="n">max_depth</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">s</span><span class="o">=</span><span class="default_value">10</span></em>, <em class="sig-param"><span class="n">njobs</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">verbose</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/RCC.html#RCC"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.RCC" title="Permalink to this definition">¶</a></dt>
<dd><p>Randomized Causation Coefficient model. 2nd approach in the Fast
Causation challenge.</p>
<p><strong>Description:</strong> The Randomized causation coefficient (RCC) relies on the
projection of the empirical distributions into a RKHS using random cosine
embeddings, then classfies the pairs using a random forest based on those
features.</p>
<p><strong>Data Type:</strong> Continuous, Categorical, Mixed</p>
<p><strong>Assumptions:</strong> This method needs a substantial amount of labelled causal
pairs to train itself. Its final performance depends on the training set
used.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>rand_coeff</strong> (<em>int</em>) – number of randomized coefficients</p></li>
<li><p><strong>nb_estimators</strong> (<em>int</em>) – number of estimators</p></li>
<li><p><strong>nb_min_leaves</strong> (<em>int</em>) – number of min samples leaves of the estimator</p></li>
<li><p><strong>(</strong><strong>)</strong> (<em>max_depth</em>) – (optional) max depth of the model</p></li>
<li><p><strong>s</strong> (<em>float</em>) – scaling</p></li>
<li><p><strong>njobs</strong> (<em>int</em>) – number of jobs to be run on parallel (defaults to <code class="docutils literal notranslate"><span class="pre">cdt.SETTINGS.NJOBS</span></code>)</p></li>
<li><p><strong>verbose</strong> (<em>bool</em>) – verbosity (defaults to <code class="docutils literal notranslate"><span class="pre">cdt.SETTINGS.verbose</span></code>)</p></li>
</ul>
</dd>
</dl>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Ref : Lopez-Paz, David and Muandet, Krikamol and Schölkopf, Bernhard and Tolstikhin, Ilya O,
“Towards a Learning Theory of Cause-Effect Inference”, ICML 2015.</p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.pairwise</span> <span class="kn">import</span> <span class="n">RCC</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sklearn.model_selection</span> <span class="kn">import</span> <span class="n">train_test_split</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">labels</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s1">&#39;tuebingen&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X_tr</span><span class="p">,</span> <span class="n">X_te</span><span class="p">,</span> <span class="n">y_tr</span><span class="p">,</span> <span class="n">y_te</span> <span class="o">=</span> <span class="n">train_test_split</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">labels</span><span class="p">,</span> <span class="n">train_size</span><span class="o">=.</span><span class="mi">5</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">RCC</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">X_tr</span><span class="p">,</span> <span class="n">y_tr</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># This example uses the predict() method</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">X_te</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># This example uses the orient_graph() method. The dataset used</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># can be loaded using the cdt.data module</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s1">&#39;sachs&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">orient_graph</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">nx</span><span class="o">.</span><span class="n">DiGraph</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># To view the directed graph run the following command</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<dl class="py method">
<dt id="cdt.causality.pairwise.RCC.featurize_row">
<code class="sig-name descname">featurize_row</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em>, <em class="sig-param"><span class="n">y</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/RCC.html#RCC.featurize_row"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.RCC.featurize_row" title="Permalink to this definition">¶</a></dt>
<dd><p>Projects the causal pair to the RKHS using the sampled kernel approximation.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> (<em>np.ndarray</em>) – Variable 1</p></li>
<li><p><strong>y</strong> (<em>np.ndarray</em>) – Variable 2</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>projected empirical distributions into a single fixed-size vector.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>np.ndarray</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.pairwise.RCC.fit">
<code class="sig-name descname">fit</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em>, <em class="sig-param"><span class="n">y</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/RCC.html#RCC.fit"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.RCC.fit" title="Permalink to this definition">¶</a></dt>
<dd><p>Train the model.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x_tr</strong> (<em>pd.DataFrame</em>) – CEPC format dataframe containing the pairs</p></li>
<li><p><strong>y_tr</strong> (<em>pd.DataFrame</em><em> or </em><em>np.ndarray</em>) – labels associated to the pairs</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.pairwise.RCC.predict_proba">
<code class="sig-name descname">predict_proba</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">dataset</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/RCC.html#RCC.predict_proba"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.RCC.predict_proba" title="Permalink to this definition">¶</a></dt>
<dd><p>Predict the causal score using a trained RCC model</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>dataset</strong> (<em>tuple</em>) – Couple of np.ndarray variables to classify</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Causation score (Value : 1 if a-&gt;b and -1 if b-&gt;a)</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>float</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="reci">
<h3><span class="hidden-section">RECI</span><a class="headerlink" href="#reci" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt id="cdt.causality.pairwise.RECI">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.pairwise.</code><code class="sig-name descname">RECI</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">degree</span><span class="o">=</span><span class="default_value">3</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/RECI.html#RECI"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.RECI" title="Permalink to this definition">¶</a></dt>
<dd><p>RECI model.</p>
<p><strong>Description:</strong> Regression Error based Causal Inference (RECI)
relies on a best-fit mse with monome regressor and [0,1] rescaling to
infer causal direction.</p>
<p><strong>Data Type:</strong> Continuous (depends on the regressor used)</p>
<p><strong>Assumptions:</strong> No independence tests are used, but the assumptions on
the model depend on the regessor used for RECI.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>degree</strong> (<em>int</em>) – Degree of the polynomial regression.</p>
</dd>
</dl>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Bloebaum, P., Janzing, D., Washio, T., Shimizu, S., &amp; Schoelkopf, B.
(2018, March). Cause-Effect Inference by Comparing Regression Errors.
In International Conference on Artificial Intelligence and Statistics (pp. 900-909).</p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.pairwise</span> <span class="kn">import</span> <span class="n">RECI</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">labels</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s1">&#39;tuebingen&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">RECI</span><span class="p">()</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># This example uses the predict() method</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># This example uses the orient_graph() method. The dataset used</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># can be loaded using the cdt.data module</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">orient_graph</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#To view the directed graph run the following command</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<dl class="py method">
<dt id="cdt.causality.pairwise.RECI.b_fit_score">
<code class="sig-name descname">b_fit_score</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span></em>, <em class="sig-param"><span class="n">y</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/RECI.html#RECI.b_fit_score"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.RECI.b_fit_score" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute the RECI fit score</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> (<em>numpy.ndarray</em>) – Variable 1</p></li>
<li><p><strong>y</strong> (<em>numpy.ndarray</em>) – Variable 2</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>RECI fit score</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>float</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.pairwise.RECI.predict_proba">
<code class="sig-name descname">predict_proba</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">dataset</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/pairwise/RECI.html#RECI.predict_proba"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.pairwise.RECI.predict_proba" title="Permalink to this definition">¶</a></dt>
<dd><p>Infer causal relationships between 2 variables using the RECI statistic</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>dataset</strong> (<em>tuple</em>) – Couple of np.ndarray variables to classify</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Causation coefficient (Value : 1 if a-&gt;b and -1 if b-&gt;a)</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>float</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
</div>
<div class="section" id="module-cdt.causality.graph">
<span id="cdt-causality-graph"></span><h2>cdt.causality.graph<a class="headerlink" href="#module-cdt.causality.graph" title="Permalink to this headline">¶</a></h2>
<p>Find causal relationships and output a directed graph.</p>
<dl class="py class">
<dt id="cdt.causality.graph.model.GraphModel">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.graph.model.</code><code class="sig-name descname">GraphModel</code><a class="reference internal" href="_modules/cdt/causality/graph/model.html#GraphModel"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.model.GraphModel" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for all graph causal inference models.</p>
<p>Usage for undirected/directed graphs and raw data. All causal discovery
models out of observational data base themselves on this class. Its main
feature is the predict function that executes a function according to the
given arguments.</p>
<dl class="py method">
<dt id="cdt.causality.graph.model.GraphModel.create_graph_from_data">
<code class="sig-name descname">create_graph_from_data</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/model.html#GraphModel.create_graph_from_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.model.GraphModel.create_graph_from_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Infer a directed graph out of data.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Not implemented: will be implemented by the model classes.</p>
</div>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.graph.model.GraphModel.orient_directed_graph">
<code class="sig-name descname">orient_directed_graph</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">dag</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/model.html#GraphModel.orient_directed_graph"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.model.GraphModel.orient_directed_graph" title="Permalink to this definition">¶</a></dt>
<dd><p>Re/Orient an undirected graph.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Not implemented: will be implemented by the model classes.</p>
</div>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.graph.model.GraphModel.orient_undirected_graph">
<code class="sig-name descname">orient_undirected_graph</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">umg</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/model.html#GraphModel.orient_undirected_graph"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.model.GraphModel.orient_undirected_graph" title="Permalink to this definition">¶</a></dt>
<dd><p>Orient an undirected graph.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Not implemented: will be implemented by the model classes.</p>
</div>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.graph.model.GraphModel.predict">
<code class="sig-name descname">predict</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">df_data</span></em>, <em class="sig-param"><span class="n">graph</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/model.html#GraphModel.predict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.model.GraphModel.predict" title="Permalink to this definition">¶</a></dt>
<dd><p>Orient a graph using the method defined by the arguments.</p>
<p>Depending on the type of <cite>graph</cite>, this function process to execute
different functions:</p>
<ol class="arabic simple">
<li><p>If <code class="docutils literal notranslate"><span class="pre">graph</span></code> is a <code class="docutils literal notranslate"><span class="pre">networkx.DiGraph</span></code>, then <code class="docutils literal notranslate"><span class="pre">self.orient_directed_graph</span></code> is executed.</p></li>
<li><p>If <code class="docutils literal notranslate"><span class="pre">graph</span></code> is a <code class="docutils literal notranslate"><span class="pre">networkx.Graph</span></code>, then <code class="docutils literal notranslate"><span class="pre">self.orient_undirected_graph</span></code> is executed.</p></li>
<li><p>If <code class="docutils literal notranslate"><span class="pre">graph</span></code> is a <code class="docutils literal notranslate"><span class="pre">None</span></code>, then <code class="docutils literal notranslate"><span class="pre">self.create_graph_from_data</span></code> is executed.</p></li>
</ol>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>df_data</strong> (<em>pandas.DataFrame</em>) – DataFrame containing the observational data.</p></li>
<li><p><strong>graph</strong> (<em>networkx.DiGraph</em><em> or </em><em>networkx.Graph</em><em> or </em><em>None</em>) – Prior knowledge on the causal graph.</p></li>
</ul>
</dd>
</dl>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Requirement : Name of the nodes in the graph must correspond to the
name of the variables in df_data</p>
</div>
</dd></dl>

</dd></dl>

<div class="section" id="bnlearn-based-models">
<h3><span class="hidden-section">bnlearn-based models</span><a class="headerlink" href="#bnlearn-based-models" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt id="cdt.causality.graph.bnlearn.BNlearnAlgorithm">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.graph.bnlearn.</code><code class="sig-name descname">BNlearnAlgorithm</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">score</span><span class="o">=</span><span class="default_value">'NULL'</span></em>, <em class="sig-param"><span class="n">alpha</span><span class="o">=</span><span class="default_value">0.05</span></em>, <em class="sig-param"><span class="n">beta</span><span class="o">=</span><span class="default_value">'NULL'</span></em>, <em class="sig-param"><span class="n">optim</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">verbose</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/bnlearn.html#BNlearnAlgorithm"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.bnlearn.BNlearnAlgorithm" title="Permalink to this definition">¶</a></dt>
<dd><p>BNlearn algorithm. All these models imported from bnlearn revolve around
this base class and have all the same attributes/interface.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>score</strong> (<em>str</em>) – the label of the conditional independence test to be used in the
algorithm. If none is specified, the default test statistic is the mutual information
for categorical variables, the Jonckheere-Terpstra test for ordered factors and the
linear correlation for continuous variables. See below for available tests.</p></li>
<li><p><strong>alpha</strong> (<em>float</em>) – a numeric value, the target nominal type I error rate.</p></li>
<li><p><strong>beta</strong> (<em>int</em>) – a positive integer, the number of permutations considered for each permutation
test. It will be ignored with a warning if the conditional independence test specified by the
score argument is not a permutation test.</p></li>
<li><p><strong>optim</strong> (<em>bool</em>) – See bnlearn-package for details.</p></li>
<li><p><strong>verbose</strong> (<em>bool</em>) – Sets the verbosity. Defaults to SETTINGS.verbose</p></li>
</ul>
</dd>
</dl>
<dl class="simple" id="bnlearntests">
<dt>Available tests:</dt><dd><ul class="simple">
<li><dl class="simple">
<dt>discrete case (categorical variables)</dt><dd><dl class="simple">
<dt>– mutual information: an information-theoretic distance measure.</dt><dd><p>It’s proportional to the log-likelihood ratio (they differ by a 2n factor)
and is related to the deviance of the tested models. The asymptotic χ2 test
(mi and mi-adf,  with  adjusted  degrees  of  freedom), the Monte Carlo
permutation test (mc-mi), the sequential Monte Carlo permutation
test (smc-mi), and the semiparametric test (sp-mi) are implemented.</p>
</dd>
<dt>– shrinkage estimator for the mutual information (mi-sh)</dt><dd><p>An improved
asymptotic χ2 test based on the James-Stein estimator for the mutual
information.</p>
</dd>
<dt>– Pearson’s X2<span class="classifier">the classical Pearson’s X2 test for contingency tables.</span></dt><dd><p>The asymptotic χ2 test (x2 and x2-adf, with adjusted degrees of freedom),
the Monte Carlo permutation test (mc-x2), the sequential Monte Carlo
permutation test (smc-x2) and semiparametric test (sp-x2) are implemented  .</p>
</dd>
</dl>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt>discrete case (ordered factors)</dt><dd><dl class="simple">
<dt>– Jonckheere-Terpstra<span class="classifier">a trend test for ordinal variables.</span></dt><dd><p>The
asymptotic normal test (jt), the Monte Carlo permutation test (mc-jt)
and the sequential Monte Carlo permutation test (smc-jt) are implemented.</p>
</dd>
</dl>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt>continuous case (normal variables)</dt><dd><dl class="simple">
<dt>– linear  correlation:  Pearson’s  linear  correlation.</dt><dd><p>The exact
Student’s  t  test  (cor),  the Monte Carlo permutation test (mc-cor)
and the sequential Monte Carlo permutation test (smc-cor) are implemented.</p>
</dd>
<dt>– Fisher’s Z: a transformation of the linear correlation with asymptotic normal distribution.</dt><dd><p>Used by commercial software (such as TETRAD II)
for the PC algorithm (an R implementation is present in the pcalg
package on CRAN). The asymptotic normal test (zf), the Monte Carlo
permutation test (mc-zf) and the sequential Monte Carlo permutation
test (smc-zf) are implemented.</p>
</dd>
<dt>– mutual information: an information-theoretic distance measure.</dt><dd><p>Again
it is proportional to the log-likelihood ratio (they differ by a 2n
factor). The asymptotic χ2 test (mi-g), the Monte Carlo permutation
test (mc-mi-g) and the sequential Monte Carlo permutation test
(smc-mi-g) are implemented.</p>
</dd>
<dt>– shrinkage estimator for the mutual information(mi-g-sh):</dt><dd><p>an improved
asymptotic χ2 test based on the James-Stein estimator for the mutual
information.</p>
</dd>
</dl>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt>hybrid case (mixed discrete and normal variables)</dt><dd><dl class="simple">
<dt>– mutual information: an information-theoretic distance measure.</dt><dd><p>Again
it is proportional to the log-likelihood ratio (they differ by a 2n
factor). Only the asymptotic χ2 test (mi-cg) is implemented.</p>
</dd>
</dl>
</dd>
</dl>
</li>
</ul>
</dd>
</dl>
<dl class="py method">
<dt id="cdt.causality.graph.bnlearn.BNlearnAlgorithm.create_graph_from_data">
<code class="sig-name descname">create_graph_from_data</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/bnlearn.html#BNlearnAlgorithm.create_graph_from_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.bnlearn.BNlearnAlgorithm.create_graph_from_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Run the algorithm on data.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>data</strong> (<em>pandas.DataFrame</em>) – DataFrame containing the data</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Solution given by the algorithm.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.graph.bnlearn.BNlearnAlgorithm.orient_directed_graph">
<code class="sig-name descname">orient_directed_graph</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">graph</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/bnlearn.html#BNlearnAlgorithm.orient_directed_graph"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.bnlearn.BNlearnAlgorithm.orient_directed_graph" title="Permalink to this definition">¶</a></dt>
<dd><p>Run the algorithm on a directed_graph.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> (<em>pandas.DataFrame</em>) – DataFrame containing the data</p></li>
<li><p><strong>graph</strong> (<em>networkx.DiGraph</em>) – Skeleton of the graph to orient</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Solution on the given skeleton.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>The algorithm is ran on the skeleton of the given graph.</p>
</div>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.graph.bnlearn.BNlearnAlgorithm.orient_undirected_graph">
<code class="sig-name descname">orient_undirected_graph</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">graph</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/bnlearn.html#BNlearnAlgorithm.orient_undirected_graph"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.bnlearn.BNlearnAlgorithm.orient_undirected_graph" title="Permalink to this definition">¶</a></dt>
<dd><p>Run the algorithm on an undirected graph.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> (<em>pandas.DataFrame</em>) – DataFrame containing the data</p></li>
<li><p><strong>graph</strong> (<em>networkx.Graph</em>) – Skeleton of the graph to orient</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Solution on the given skeleton.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

<div class="section" id="gs">
<h4><span class="hidden-section">GS</span><a class="headerlink" href="#gs" title="Permalink to this headline">¶</a></h4>
<dl class="py class">
<dt id="cdt.causality.graph.bnlearn.GS">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.graph.bnlearn.</code><code class="sig-name descname">GS</code><a class="reference internal" href="_modules/cdt/causality/graph/bnlearn.html#GS"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.bnlearn.GS" title="Permalink to this definition">¶</a></dt>
<dd><p>Grow-Shrink algorithm.</p>
<p><strong>Description:</strong> The Grow Shrink algorithm is a constraint based algorithm
to recover bayesian networks. It consists in two phases, one growing phase
in which nodes are added to the markov blanket based on conditional
independence and a shrinking phase in which most irrelevant nodes are
removed.</p>
<p><strong>Required R packages</strong>: bnlearn</p>
<p><strong>Data Type:</strong> Depends on the test used. Check
<a class="reference internal" href="#bnlearntests"><span class="std std-ref">here</span></a> for the list of available tests.</p>
<p><strong>Assumptions:</strong> GS outputs a CPDAG, with additional assumptions depending
on the conditional test used.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Margaritis D (2003).
Learning Bayesian Network Model Structure from Data
. Ph.D. thesis, School
of Computer Science, Carnegie-Mellon University, Pittsburgh, PA. Available as Technical Report
CMU-CS-03-153</p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.graph</span> <span class="kn">import</span> <span class="n">GS</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">GS</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#The predict() method works without a graph, or with a</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#directed or undirected graph provided as an input</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>    <span class="c1">#No graph provided as an argument</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>  <span class="c1">#With an undirected graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span><span class="p">)</span>  <span class="c1">#With a directed graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#To view the graph created, run the below commands:</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="iamb">
<h4><span class="hidden-section">IAMB</span><a class="headerlink" href="#iamb" title="Permalink to this headline">¶</a></h4>
<dl class="py class">
<dt id="cdt.causality.graph.bnlearn.IAMB">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.graph.bnlearn.</code><code class="sig-name descname">IAMB</code><a class="reference internal" href="_modules/cdt/causality/graph/bnlearn.html#IAMB"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.bnlearn.IAMB" title="Permalink to this definition">¶</a></dt>
<dd><p>IAMB algorithm.</p>
<p><strong>Description:</strong> The is a bayesian constraint based algorithm
to recover Markov blankets in a forward selection and a modified backward
selection process.</p>
<p><strong>Required R packages</strong>: bnlearn</p>
<p><strong>Data Type:</strong> Depends on the test used. Check
<a class="reference internal" href="#bnlearntests"><span class="std std-ref">here</span></a> for the list of available tests.</p>
<p><strong>Assumptions:</strong> IAMB outputs Markov blankets of nodes,
with additional assumptions depending on the conditional test used.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Tsamardinos  I,  Aliferis  CF,  Statnikov  A  (2003).   “Algorithms  for  Large  Scale  Markov  Blanket
Discovery”.  In “Proceedings of the Sixteenth International Florida Artificial Intelligence Research
Society Conference”, pp. 376-381. AAAI Press.</p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.graph</span> <span class="kn">import</span> <span class="n">IAMB</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">IAMB</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#The predict() method works without a graph, or with a</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#directed or undirected graph provided as an input</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>    <span class="c1">#No graph provided as an argument</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>  <span class="c1">#With an undirected graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span><span class="p">)</span>  <span class="c1">#With a directed graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#To view the graph created, run the below commands:</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="fast-iamb">
<h4><span class="hidden-section">Fast_IAMB</span><a class="headerlink" href="#fast-iamb" title="Permalink to this headline">¶</a></h4>
<dl class="py class">
<dt id="cdt.causality.graph.bnlearn.Fast_IAMB">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.graph.bnlearn.</code><code class="sig-name descname">Fast_IAMB</code><a class="reference internal" href="_modules/cdt/causality/graph/bnlearn.html#Fast_IAMB"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.bnlearn.Fast_IAMB" title="Permalink to this definition">¶</a></dt>
<dd><p>Fast IAMB algorithm.</p>
<p><strong>Description:</strong> Similar to IAMB, Fast-IAMB adds speculation to provide more
computational performance without affecting the accuracy of markov blanket
recovery.</p>
<p><strong>Required R packages</strong>: bnlearn</p>
<p><strong>Data Type:</strong> Depends on the test used. Check
<a class="reference internal" href="#bnlearntests"><span class="std std-ref">here</span></a> for the list of available tests.</p>
<p><strong>Assumptions:</strong> Fast-IAMB outputs markov blankets of nodes, with additional
assumptions depending on the conditional test used.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Yaramakala S, Margaritis D (2005).  “Speculative Markov Blanket Discovery for Optimal Feature
Selection”.  In “ICDM ’05:  Proceedings of the Fifth IEEE International Conference on Data
Mining”, pp. 809-812. IEEE Computer Society.</p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.graph</span> <span class="kn">import</span> <span class="n">Fast_IAMB</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">Fast_IAMB</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#The predict() method works without a graph, or with a</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#directed or undirected graph provided as an input</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>    <span class="c1">#No graph provided as an argument</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>  <span class="c1">#With an undirected graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span><span class="p">)</span>  <span class="c1">#With a directed graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#To view the graph created, run the below commands:</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="inter-iamb">
<h4><span class="hidden-section">Inter_IAMB</span><a class="headerlink" href="#inter-iamb" title="Permalink to this headline">¶</a></h4>
<dl class="py class">
<dt id="cdt.causality.graph.bnlearn.Inter_IAMB">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.graph.bnlearn.</code><code class="sig-name descname">Inter_IAMB</code><a class="reference internal" href="_modules/cdt/causality/graph/bnlearn.html#Inter_IAMB"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.bnlearn.Inter_IAMB" title="Permalink to this definition">¶</a></dt>
<dd><p>Interleaved IAMB algorithm.</p>
<p><strong>Description:</strong> Similar to IAMB, Interleaved-IAMB has a progressive
forward selection minimizing false positives.</p>
<p><strong>Required R packages</strong>: bnlearn</p>
<p><strong>Data Type:</strong> Depends on the test used. Check
<a class="reference internal" href="#bnlearntests"><span class="std std-ref">here</span></a> for the list of available tests.</p>
<p><strong>Assumptions:</strong> Inter-IAMB outputs markov blankets of nodes, with additional
assumptions depending on the conditional test used.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Yaramakala S, Margaritis D (2005).  “Speculative Markov Blanket Discovery for Optimal Feature
Selection”.  In “ICDM ’05:  Proceedings of the Fifth IEEE International Conference on Data Min-
ing”, pp. 809-812. IEEE Computer Society.</p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.graph</span> <span class="kn">import</span> <span class="n">Inter_IAMB</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">Inter_IAMB</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#The predict() method works without a graph, or with a</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#directed or undirected graph provided as an input</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>    <span class="c1">#No graph provided as an argument</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>  <span class="c1">#With an undirected graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span><span class="p">)</span>  <span class="c1">#With a directed graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#To view the graph created, run the below commands:</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="mmpc">
<h4><span class="hidden-section">MMPC</span><a class="headerlink" href="#mmpc" title="Permalink to this headline">¶</a></h4>
<dl class="py class">
<dt id="cdt.causality.graph.bnlearn.MMPC">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.graph.bnlearn.</code><code class="sig-name descname">MMPC</code><a class="reference internal" href="_modules/cdt/causality/graph/bnlearn.html#MMPC"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.bnlearn.MMPC" title="Permalink to this definition">¶</a></dt>
<dd><p>Max-Min Parents-Children algorithm.</p>
<p><strong>Description:</strong> The Max-Min Parents-Children (MMPC) is a 2-phase algorithm
with a forward pass and a backward pass. The forward phase adds recursively
the variables that possess the highest association with the target
conditionally to the already selected variables. The backward pass tests
d-separability of variables conditionally to the set and subsets of the
selected variables.</p>
<p><strong>Required R packages</strong>: bnlearn</p>
<p><strong>Data Type:</strong> Depends on the test used. Check
<a class="reference internal" href="#bnlearntests"><span class="std std-ref">here</span></a> for the list of available tests.</p>
<p><strong>Assumptions:</strong> MMPC outputs markov blankets of nodes, with additional
assumptions depending on the conditional test used.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Tsamardinos I, Aliferis CF, Statnikov A (2003). “Time and Sample Efficient Discovery of Markov
Blankets and Direct Causal Relations”.  In “KDD ’03:  Proceedings of the Ninth ACM SIGKDD
International Conference on Knowledge Discovery and Data Mining”, pp. 673-678. ACM.
Tsamardinos I, Brown LE, Aliferis CF (2006).  “The Max-Min Hill-Climbing Bayesian Network
Structure Learning Algorithm”.
Machine Learning,65(1), 31-78.</p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.graph</span> <span class="kn">import</span> <span class="n">MMPC</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">MMPC</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#The predict() method works without a graph, or with a</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#directed or undirected graph provided as an input</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>    <span class="c1">#No graph provided as an argument</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>  <span class="c1">#With an undirected graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span><span class="p">)</span>  <span class="c1">#With a directed graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#To view the graph created, run the below commands:</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

</div>
</div>
<div class="section" id="cam">
<h3><span class="hidden-section">CAM</span><a class="headerlink" href="#cam" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt id="cdt.causality.graph.CAM">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.graph.</code><code class="sig-name descname">CAM</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">score</span><span class="o">=</span><span class="default_value">'nonlinear'</span></em>, <em class="sig-param"><span class="n">cutoff</span><span class="o">=</span><span class="default_value">0.001</span></em>, <em class="sig-param"><span class="n">variablesel</span><span class="o">=</span><span class="default_value">True</span></em>, <em class="sig-param"><span class="n">selmethod</span><span class="o">=</span><span class="default_value">'gamboost'</span></em>, <em class="sig-param"><span class="n">pruning</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">prunmethod</span><span class="o">=</span><span class="default_value">'gam'</span></em>, <em class="sig-param"><span class="n">njobs</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">verbose</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/CAM.html#CAM"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.CAM" title="Permalink to this definition">¶</a></dt>
<dd><p>CAM algorithm <strong>[R model]</strong>.</p>
<p><strong>Description:</strong> Causal Additive models, a causal discovery algorithm
relying on fitting Gaussian Processes on data, while considering all noises
additives and additive contributions of variables.</p>
<p><strong>Required R packages</strong>: CAM</p>
<p><strong>Data Type:</strong> Continuous</p>
<p><strong>Assumptions:</strong> The data follows a generalized additive noise model:
each variable <span class="math notranslate nohighlight">\(X_i\)</span>  in the graph <span class="math notranslate nohighlight">\(\mathcal{G}\)</span> is generated
following the model <span class="math notranslate nohighlight">\(X_i = \sum_{X_j \in \mathcal{G}} f(X_j) + \epsilon_i\)</span>,
<span class="math notranslate nohighlight">\(\epsilon_i\)</span> representing mutually independent noises variables
accounting for unobserved variables.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>score</strong> (<em>str</em>) – Score used to fit the gaussian processes.</p></li>
<li><p><strong>cutoff</strong> (<em>float</em>) – threshold value for variable selection.</p></li>
<li><p><strong>variablesel</strong> (<em>bool</em>) – Perform a variable selection step.</p></li>
<li><p><strong>selmethod</strong> (<em>str</em>) – Method used for variable selection.</p></li>
<li><p><strong>pruning</strong> (<em>bool</em>) – Perform an initial pruning step.</p></li>
<li><p><strong>prunmethod</strong> (<em>str</em>) – Method used for pruning.</p></li>
<li><p><strong>njobs</strong> (<em>int</em>) – Number of jobs to run in parallel.</p></li>
<li><p><strong>verbose</strong> (<em>bool</em>) – Sets the verbosity of the output.</p></li>
</ul>
</dd>
</dl>
<dl class="simple">
<dt>Available scores:</dt><dd><ul class="simple">
<li><p>nonlinear: ‘SEMGAM’</p></li>
<li><p>linear: ‘SEMLIN’</p></li>
</ul>
</dd>
<dt>Available variable selection methods:</dt><dd><ul class="simple">
<li><p>gamboost’: ‘selGamBoost’</p></li>
<li><p>gam’: ‘selGam’</p></li>
<li><p>lasso’: ‘selLasso’</p></li>
<li><p>linear’: ‘selLm’</p></li>
<li><p>linearboost’: ‘selLmBoost’</p></li>
</ul>
</dd>
<dt>Default Parameters:</dt><dd><ul class="simple">
<li><p>FILE: ‘/tmp/cdt_CAM/data.csv’</p></li>
<li><p>SCORE: ‘SEMGAM’</p></li>
<li><p>VARSEL: ‘TRUE’</p></li>
<li><p>SELMETHOD: ‘selGamBoost’</p></li>
<li><p>PRUNING: ‘TRUE’</p></li>
<li><p>PRUNMETHOD: ‘selGam’</p></li>
<li><p>NJOBS: str(SETTINGS.NJOBS)</p></li>
<li><p>CUTOFF: str(0.001)</p></li>
<li><p>VERBOSE: ‘FALSE’</p></li>
<li><p>OUTPUT: ‘/tmp/cdt_CAM/result.csv’</p></li>
</ul>
</dd>
</dl>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Ref:
Bühlmann, P., Peters, J., &amp; Ernest, J. (2014). CAM: Causal additive
models, high-dimensional order search and penalized regression. The
Annals of Statistics, 42(6), 2526-2556.</p>
</div>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>This implementation of CAM does not support starting with a graph.
The adaptation will be made at a later date.</p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.graph</span> <span class="kn">import</span> <span class="n">CAM</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">CAM</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
</pre></div>
</div>
<dl class="py method">
<dt id="cdt.causality.graph.CAM.create_graph_from_data">
<code class="sig-name descname">create_graph_from_data</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/CAM.html#CAM.create_graph_from_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.CAM.create_graph_from_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Apply causal discovery on observational data using CAM.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>data</strong> (<em>pandas.DataFrame</em>) – DataFrame containing the data</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Solution given by the CAM algorithm.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="ccdr">
<h3><span class="hidden-section">CCDr</span><a class="headerlink" href="#ccdr" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt id="cdt.causality.graph.CCDr">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.graph.</code><code class="sig-name descname">CCDr</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">verbose</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/CCDr.html#CCDr"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.CCDr" title="Permalink to this definition">¶</a></dt>
<dd><p>CCDr algorithm <strong>[R model]</strong>.</p>
<p><strong>Description:</strong> Concave penalized Coordinate Descent with reparametrization) structure
learning algorithm as described in Aragam and Zhou (2015). This is a fast,
score based method for learning Bayesian networks that uses sparse
regularization and block-cyclic coordinate descent.</p>
<p><strong>Required R packages</strong>: sparsebn</p>
<p><strong>Data Type:</strong> Continuous</p>
<p><strong>Assumptions:</strong> This model does not restrict or prune the search space in
any way, does not assume faithfulness, does not require a known variable
ordering, works on observational data (i.e. without experimental
interventions), works effectively in high dimensions, and is capable of
handling graphs with several thousand variables. The output of this model
is a DAG.</p>
<p>Imported from the ‘sparsebn’ package.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>This implementation of CCDr does not support starting with a graph.</p>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>ref: Aragam, B., &amp; Zhou, Q. (2015). Concave penalized estimation of
sparse Gaussian Bayesian networks. Journal of Machine Learning Research,
16, 2273-2328.</p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.graph</span> <span class="kn">import</span> <span class="n">CCDr</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">CCCDr</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
</pre></div>
</div>
<dl class="py method">
<dt id="cdt.causality.graph.CCDr.create_graph_from_data">
<code class="sig-name descname">create_graph_from_data</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/CCDr.html#CCDr.create_graph_from_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.CCDr.create_graph_from_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Apply causal discovery on observational data using CCDr.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>data</strong> (<em>pandas.DataFrame</em>) – DataFrame containing the data</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Solution given by the CCDR algorithm.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="cgnn">
<h3><span class="hidden-section">CGNN</span><a class="headerlink" href="#cgnn" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt id="cdt.causality.graph.CGNN">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.graph.</code><code class="sig-name descname">CGNN</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">nh</span><span class="o">=</span><span class="default_value">20</span></em>, <em class="sig-param"><span class="n">nruns</span><span class="o">=</span><span class="default_value">16</span></em>, <em class="sig-param"><span class="n">njobs</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">gpus</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">batch_size</span><span class="o">=</span><span class="default_value">- 1</span></em>, <em class="sig-param"><span class="n">lr</span><span class="o">=</span><span class="default_value">0.01</span></em>, <em class="sig-param"><span class="n">train_epochs</span><span class="o">=</span><span class="default_value">1000</span></em>, <em class="sig-param"><span class="n">test_epochs</span><span class="o">=</span><span class="default_value">1000</span></em>, <em class="sig-param"><span class="n">verbose</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">dataloader_workers</span><span class="o">=</span><span class="default_value">0</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/CGNN.html#CGNN"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.CGNN" title="Permalink to this definition">¶</a></dt>
<dd><p>Causal Generative Neural Netwoks</p>
<p><strong>Description:</strong> Causal Generative Neural Networks. Score-method that
evaluates candidate graph by generating data following the topological
order of the graph using neural networks, and using MMD for evaluation.</p>
<p><strong>Data Type:</strong> Continuous</p>
<p><strong>Assumptions:</strong> The class of generative models is not restricted with a
hard contraint, but with the hyperparameter <code class="docutils literal notranslate"><span class="pre">nh</span></code>. This algorithm greatly
benefits from bootstrapped runs (nruns &gt;=12 recommended), and is very
computationnally heavy. GPUs are recommended.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>nh</strong> (<em>int</em>) – Number of hidden units in each generative neural network.</p></li>
<li><p><strong>nruns</strong> (<em>int</em>) – Number of times to run CGNN to have a stable
evaluation.</p></li>
<li><p><strong>njobs</strong> (<em>int</em>) – Number of jobs to run in parallel. Defaults to
<code class="docutils literal notranslate"><span class="pre">cdt.SETTINGS.NJOBS</span></code>.</p></li>
<li><p><strong>gpus</strong> (<em>bool</em>) – Number of available gpus
(Initialized with <code class="docutils literal notranslate"><span class="pre">cdt.SETTINGS.GPU</span></code>)</p></li>
<li><p><strong>batch_size</strong> (<em>int</em>) – batch size, defaults to full-batch</p></li>
<li><p><strong>lr</strong> (<em>float</em>) – Learning rate for the generative neural networks.</p></li>
<li><p><strong>train_epochs</strong> (<em>int</em>) – Number of epochs used to train the network.</p></li>
<li><p><strong>test_epochs</strong> (<em>int</em>) – Number of epochs during which the results are
harvested. The network still trains at this stage.</p></li>
<li><p><strong>verbose</strong> (<em>bool</em>) – Sets the verbosity of the execution. Defaults to
<code class="docutils literal notranslate"><span class="pre">cdt.SETTINGS.verbose</span></code>.</p></li>
<li><p><strong>dataloader_workers</strong> (<em>int</em>) – how many subprocesses to use for data
loading. 0 means that the data will be loaded in the main
process. (default: 0)</p></li>
</ul>
</dd>
</dl>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Ref : Learning Functional Causal Models with Generative Neural Networks
Olivier Goudet &amp; Diviyan Kalainathan &amp; Al.
(<a class="reference external" href="https://arxiv.org/abs/1709.05321">https://arxiv.org/abs/1709.05321</a>)</p>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The input data can be of type torch.utils.data.Dataset, or it defaults to
<cite>cdt.utils.io.MetaDataset</cite>. This class is overridable to write custom
data loading functions, useful for very large datasets.</p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.graph</span> <span class="kn">import</span> <span class="n">CGNN</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">CGNN</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#The predict() method works without a graph, or with a</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#directed or undirected graph provided as an input</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>    <span class="c1">#No graph provided as an argument</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>  <span class="c1">#With an undirected graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span><span class="p">)</span>  <span class="c1">#With a directed graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#To view the graph created, run the below commands:</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<dl class="py method">
<dt id="cdt.causality.graph.CGNN.create_graph_from_data">
<code class="sig-name descname">create_graph_from_data</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/CGNN.html#CGNN.create_graph_from_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.CGNN.create_graph_from_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Use CGNN to create a graph from scratch. All the possible structures
are tested, which leads to a super exponential complexity. It would be
preferable to start from a graph skeleton for large graphs.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>data</strong> (<em>pandas.DataFrame</em><em> or </em><em>torch.utils.data.Dataset</em>) – Observational
data on which causal discovery has to be performed.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Solution given by CGNN.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.graph.CGNN.orient_directed_graph">
<code class="sig-name descname">orient_directed_graph</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">dag</span></em>, <em class="sig-param"><span class="n">alg</span><span class="o">=</span><span class="default_value">'HC'</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/CGNN.html#CGNN.orient_directed_graph"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.CGNN.orient_directed_graph" title="Permalink to this definition">¶</a></dt>
<dd><p>Modify and improve a directed acyclic graph solution using CGNN.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> (<em>pandas.DataFrame</em><em> or </em><em>torch.utils.data.Dataset</em>) – Observational
data on which causal discovery has to be performed.</p></li>
<li><p><strong>dag</strong> (<em>nx.DiGraph</em>) – Graph that provides the initial solution,
on which the CGNN algorithm will be applied.</p></li>
<li><p><strong>alg</strong> (<em>str</em>) – Exploration heuristic to use, only “HC” is supported for
now.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Solution given by CGNN.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.graph.CGNN.orient_undirected_graph">
<code class="sig-name descname">orient_undirected_graph</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">umg</span></em>, <em class="sig-param"><span class="n">alg</span><span class="o">=</span><span class="default_value">'HC'</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/CGNN.html#CGNN.orient_undirected_graph"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.CGNN.orient_undirected_graph" title="Permalink to this definition">¶</a></dt>
<dd><p>Orient the undirected graph using GNN and apply CGNN to improve the graph.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> (<em>pandas.DataFrame</em>) – Observational data on which causal
discovery has to be performed.</p></li>
<li><p><strong>umg</strong> (<em>nx.Graph</em>) – Graph that provides the skeleton, on which the GNN
then the CGNN algorithm will be applied.</p></li>
<li><p><strong>alg</strong> (<em>str</em>) – Exploration heuristic to use, only “HC” is supported for
now.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Solution given by CGNN.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>GNN (<code class="docutils literal notranslate"><span class="pre">cdt.causality.pairwise.GNN</span></code>) is first used to orient the
undirected graph and output a DAG before applying CGNN.</p>
</div>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="ges">
<h3><span class="hidden-section">GES</span><a class="headerlink" href="#ges" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt id="cdt.causality.graph.GES">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.graph.</code><code class="sig-name descname">GES</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">score</span><span class="o">=</span><span class="default_value">'obs'</span></em>, <em class="sig-param"><span class="n">verbose</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/GES.html#GES"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.GES" title="Permalink to this definition">¶</a></dt>
<dd><p>GES algorithm <strong>[R model]</strong>.</p>
<p><strong>Description:</strong> Greedy Equivalence Search algorithm. A score-based
Bayesian algorithm that searches heuristically the graph which minimizes
a likelihood score on the data.</p>
<p><strong>Required R packages</strong>: pcalg</p>
<p><strong>Data Type:</strong> Continuous (<code class="docutils literal notranslate"><span class="pre">score='obs'</span></code>) or Categorical (<code class="docutils literal notranslate"><span class="pre">score='int'</span></code>)</p>
<p><strong>Assumptions:</strong> The output is a Partially Directed Acyclic Graph (PDAG)
(A markov equivalence class). The available scores assume linearity of
mechanisms and gaussianity of the data.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>score</strong> (<em>str</em>) – Sets the score used by GES.</p></li>
<li><p><strong>verbose</strong> (<em>bool</em>) – Defaults to <code class="docutils literal notranslate"><span class="pre">cdt.SETTINGS.verbose</span></code>.</p></li>
</ul>
</dd>
</dl>
<dl class="simple">
<dt>Available scores:</dt><dd><ul class="simple">
<li><p>int: GaussL0penIntScore</p></li>
<li><p>obs: GaussL0penObsScore</p></li>
</ul>
</dd>
</dl>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Ref:
D.M. Chickering (2002).  Optimal structure identification with greedy search.
Journal of Machine Learning Research 3 , 507–554</p>
<p>A. Hauser and P. Bühlmann (2012). Characterization and greedy learning of
interventional Markov equivalence classes of directed acyclic graphs.
Journal of Machine Learning Research 13, 2409–2464.</p>
<p>P. Nandy, A. Hauser and M. Maathuis (2015). Understanding consistency in
hybrid causal structure learning.
arXiv preprint 1507.02608</p>
<p>P. Spirtes, C.N. Glymour, and R. Scheines (2000).
Causation, Prediction, and Search, MIT Press, Cambridge (MA)</p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.graph</span> <span class="kn">import</span> <span class="n">GES</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">GES</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#The predict() method works without a graph, or with a</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#directed or udirected graph provided as an input</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>    <span class="c1">#No graph provided as an argument</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>  <span class="c1">#With an undirected graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span><span class="p">)</span>  <span class="c1">#With a directed graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#To view the graph created, run the below commands:</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<dl class="py method">
<dt id="cdt.causality.graph.GES.create_graph_from_data">
<code class="sig-name descname">create_graph_from_data</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/GES.html#GES.create_graph_from_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.GES.create_graph_from_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Run the GES algorithm.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>data</strong> (<em>pandas.DataFrame</em>) – DataFrame containing the data</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Solution given by the GES algorithm.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.graph.GES.orient_directed_graph">
<code class="sig-name descname">orient_directed_graph</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">graph</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/GES.html#GES.orient_directed_graph"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.GES.orient_directed_graph" title="Permalink to this definition">¶</a></dt>
<dd><p>Run GES on a directed graph.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> (<em>pandas.DataFrame</em>) – DataFrame containing the data</p></li>
<li><p><strong>graph</strong> (<em>networkx.DiGraph</em>) – Skeleton of the graph to orient</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Solution given by the GES algorithm.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.graph.GES.orient_undirected_graph">
<code class="sig-name descname">orient_undirected_graph</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">graph</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/GES.html#GES.orient_undirected_graph"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.GES.orient_undirected_graph" title="Permalink to this definition">¶</a></dt>
<dd><p>Run GES on an undirected graph.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> (<em>pandas.DataFrame</em>) – DataFrame containing the data</p></li>
<li><p><strong>graph</strong> (<em>networkx.Graph</em>) – Skeleton of the graph to orient</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Solution given by the GES algorithm.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="gies">
<h3><span class="hidden-section">GIES</span><a class="headerlink" href="#gies" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt id="cdt.causality.graph.GIES">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.graph.</code><code class="sig-name descname">GIES</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">score</span><span class="o">=</span><span class="default_value">'obs'</span></em>, <em class="sig-param"><span class="n">verbose</span><span class="o">=</span><span class="default_value">False</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/GIES.html#GIES"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.GIES" title="Permalink to this definition">¶</a></dt>
<dd><p>GIES algorithm <strong>[R model]</strong>.</p>
<p><strong>Description:</strong> Greedy Interventional Equivalence Search algorithm.
A score-based Bayesian algorithm that searches heuristically the graph which minimizes
a likelihood score on the data. The main difference with GES is that it
accepts interventional data for its inference.</p>
<p><strong>Required R packages</strong>: pcalg</p>
<p><strong>Data Type:</strong> Continuous (<code class="docutils literal notranslate"><span class="pre">score='obs'</span></code>) or Categorical (<code class="docutils literal notranslate"><span class="pre">score='int'</span></code>)</p>
<p><strong>Assumptions:</strong> The output is a Partially Directed Acyclic Graph (PDAG)
(A markov equivalence class). The available scores assume linearity of
mechanisms and gaussianity of the data.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>score</strong> (<em>str</em>) – Sets the score used by GIES.</p></li>
<li><p><strong>verbose</strong> (<em>bool</em>) – Defaults to <code class="docutils literal notranslate"><span class="pre">cdt.SETTINGS.verbose</span></code>.</p></li>
</ul>
</dd>
</dl>
<dl class="simple">
<dt>Available scores:</dt><dd><ul class="simple">
<li><p>int: GaussL0penIntScore</p></li>
<li><p>obs: GaussL0penObsScore</p></li>
</ul>
</dd>
</dl>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Ref:
D.M. Chickering (2002).  Optimal structure identification with greedy search.
Journal of Machine Learning Research 3 , 507–554</p>
<p>A. Hauser and P. Bühlmann (2012). Characterization and greedy learning of
interventional Markov equivalence classes of directed acyclic graphs.
Journal of Machine Learning Research 13, 2409–2464.</p>
<p>P. Nandy, A. Hauser and M. Maathuis (2015). Understanding consistency in
hybrid causal structure learning.
arXiv preprint 1507.02608</p>
<p>P. Spirtes, C.N. Glymour, and R. Scheines (2000).
Causation, Prediction, and Search, MIT Press, Cambridge (MA)</p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.graph</span> <span class="kn">import</span> <span class="n">GIES</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">GIES</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#The predict() method works without a graph, or with a</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#directed or undirected graph provided as an input</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>    <span class="c1">#No graph provided as an argument</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>  <span class="c1">#With an undirected graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span><span class="p">)</span>  <span class="c1">#With a directed graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#To view the graph created, run the below commands:</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<dl class="py method">
<dt id="cdt.causality.graph.GIES.create_graph_from_data">
<code class="sig-name descname">create_graph_from_data</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/GIES.html#GIES.create_graph_from_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.GIES.create_graph_from_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Run the GIES algorithm.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>data</strong> (<em>pandas.DataFrame</em>) – DataFrame containing the data</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Solution given by the GIES algorithm.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.graph.GIES.orient_directed_graph">
<code class="sig-name descname">orient_directed_graph</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">graph</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/GIES.html#GIES.orient_directed_graph"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.GIES.orient_directed_graph" title="Permalink to this definition">¶</a></dt>
<dd><p>Run GIES on a directed_graph.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> (<em>pandas.DataFrame</em>) – DataFrame containing the data</p></li>
<li><p><strong>graph</strong> (<em>networkx.DiGraph</em>) – Skeleton of the graph to orient</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Solution given by the GIES algorithm.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.graph.GIES.orient_undirected_graph">
<code class="sig-name descname">orient_undirected_graph</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">graph</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/GIES.html#GIES.orient_undirected_graph"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.GIES.orient_undirected_graph" title="Permalink to this definition">¶</a></dt>
<dd><p>Run GIES on an undirected graph.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> (<em>pandas.DataFrame</em>) – DataFrame containing the data</p></li>
<li><p><strong>graph</strong> (<em>networkx.Graph</em>) – Skeleton of the graph to orient</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Solution given by the GIES algorithm.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="lingam">
<h3><span class="hidden-section">LiNGAM</span><a class="headerlink" href="#lingam" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt id="cdt.causality.graph.LiNGAM">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.graph.</code><code class="sig-name descname">LiNGAM</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">verbose</span><span class="o">=</span><span class="default_value">False</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/LiNGAM.html#LiNGAM"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.LiNGAM" title="Permalink to this definition">¶</a></dt>
<dd><p>LiNGAM algorithm <strong>[R model]</strong>.</p>
<p><strong>Description:</strong> Linear Non-Gaussian Acyclic model. LiNGAM handles linear
structural equation models, where each variable is modeled as
<span class="math notranslate nohighlight">\(X_j = \sum_k \alpha_k P_a^{k}(X_j) + E_j,  j \in [1,d]\)</span>,
with  <span class="math notranslate nohighlight">\(P_a^{k}(X_j)\)</span> the <span class="math notranslate nohighlight">\(k\)</span>-th parent of
<span class="math notranslate nohighlight">\(X_j\)</span> and <span class="math notranslate nohighlight">\(\alpha_k\)</span> a real scalar.</p>
<p><strong>Required R packages</strong>: pcalg</p>
<p><strong>Data Type:</strong> Continuous</p>
<p><strong>Assumptions:</strong> The underlying causal model is supposed to be composed of
linear mechanisms and non-gaussian data. Under those assumptions, it is
shown that causal structure is fully identifiable (even inside the Markov
equivalence class).</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>verbose</strong> (<em>bool</em>) – Sets the verbosity of the algorithm. Defaults to
<cite>cdt.SETTINGS.verbose</cite></p>
</dd>
</dl>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Ref: S.  Shimizu,  P.O.  Hoyer,  A.  Hyvärinen,  A.  Kerminen  (2006)
A  Linear  Non-Gaussian  Acyclic Model for Causal Discovery;
Journal of Machine Learning Research 7, 2003–2030.</p>
</div>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>This implementation of LiNGAM does not support starting with a graph.</p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.graph</span> <span class="kn">import</span> <span class="n">LiNGAM</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">LiNGAM</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
</pre></div>
</div>
<dl class="py method">
<dt id="cdt.causality.graph.LiNGAM.create_graph_from_data">
<code class="sig-name descname">create_graph_from_data</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/LiNGAM.html#LiNGAM.create_graph_from_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.LiNGAM.create_graph_from_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Run the LiNGAM algorithm.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>data</strong> (<em>pandas.DataFrame</em>) – DataFrame containing the data</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Prediction given by the LiNGAM algorithm.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="pc">
<h3><span class="hidden-section">PC</span><a class="headerlink" href="#pc" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt id="cdt.causality.graph.PC">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.graph.</code><code class="sig-name descname">PC</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">CItest</span><span class="o">=</span><span class="default_value">'gaussian'</span></em>, <em class="sig-param"><span class="n">method_indep</span><span class="o">=</span><span class="default_value">'corr'</span></em>, <em class="sig-param"><span class="n">alpha</span><span class="o">=</span><span class="default_value">0.01</span></em>, <em class="sig-param"><span class="n">njobs</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">verbose</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/PC.html#PC"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.PC" title="Permalink to this definition">¶</a></dt>
<dd><p>PC algorithm <strong>[R model]</strong>.</p>
<p><strong>Description:</strong> PC (Peter - Clark) One of the most famous score based
approaches for causal discovery. Based on conditional tests on variables
and sets of variables, it proved itself to be really efficient.</p>
<p><strong>Required R packages</strong>: pcalg, kpcalg, RCIT (variant, see notes)</p>
<p><strong>Data Type:</strong> Continuous and discrete</p>
<p><strong>Assumptions:</strong> This approach’s complexity grows rapidly with the number
of variables, even for quick tests. Consider graphs &lt; 200 variables.
The model assumptions made by this approch mainly depend on the type of
test used. Kernel-based tests are also available. The prediction of PC
is a CPDAG (identifiability up to the Markov equivalence class).</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>CItest</strong> (<em>str</em>) – Test for conditional independence.</p></li>
<li><p><strong>alpha</strong> (<em>float</em>) – significance level (number in (0, 1) for the individual
conditional independence tests.</p></li>
<li><p><strong>njobs</strong> (<em>int</em>) – number of processor cores to use for parallel computation.
Only available for method = “stable.fast” (set as default).</p></li>
<li><p><strong>verbose</strong> – if TRUE, detailed output is provided.</p></li>
</ul>
</dd>
<dt class="field-even">Variables</dt>
<dd class="field-even"><ul class="simple">
<li><p><strong>arguments</strong> (<em>dict</em>) – contains all current parameters used in the PC
algorithm execution.</p></li>
<li><p><strong>dir_CI_test</strong> (<em>dict</em>) – contains all available conditional independence
tests.</p></li>
<li><p><strong>dir_method_indep</strong> (<em>dict</em>) – contains all available heuristics for CI
testing.</p></li>
</ul>
</dd>
</dl>
<dl class="simple">
<dt>Available CI tests:</dt><dd><ul class="simple">
<li><p>binary: “data=X, ic.method=”dcc””</p></li>
<li><p>discrete: “data=X, ic.method=”dcc””</p></li>
<li><p>hsic_gamma: “data=X, ic.method=”hsic.gamma””</p></li>
<li><p>hsic_perm: “data=X, ic.method=”hsic.perm””</p></li>
<li><p>hsic_clust: “data=X, ic.method=”hsic.clust””</p></li>
<li><p>gaussian: “C = cor(X), n = nrow(X)”</p></li>
<li><p>rcit: “data=X, ic.method=”RCIT::RCIT””</p></li>
<li><p>rcot: “data=X, ic.method=”RCIT::RCoT””</p></li>
</ul>
</dd>
<dt>Default Parameters:</dt><dd><ul class="simple">
<li><p>FILE: ‘/tmp/cdt_pc/data.csv’</p></li>
<li><p>SKELETON: ‘FALSE’</p></li>
<li><p>EDGES: ‘/tmp/cdt_pc/fixededges.csv’</p></li>
<li><p>GAPS: ‘/tmp/cdt_pc/fixedgaps.csv’</p></li>
<li><p>CITEST: “pcalg::gaussCItest”</p></li>
<li><p>METHOD_INDEP: “C = cor(X), n = nrow(X)”</p></li>
<li><p>SELMAT: ‘NULL’</p></li>
<li><p>DIRECTED: ‘TRUE’</p></li>
<li><p>SETOPTIONS: ‘NULL’</p></li>
<li><p>ALPHA: ‘0.01’</p></li>
<li><p>VERBOSE: ‘FALSE’</p></li>
<li><p>OUTPUT: ‘/tmp/cdt_pc/result.csv’</p></li>
</ul>
</dd>
</dl>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Ref:
D.Colombo and M.H. Maathuis (2014).
Order-independent constraint-based causal structure learning.
Journal of Machine Learning Research 15 3741-3782.</p>
<p>M. Kalisch, M. Maechler, D. Colombo, M.H. Maathuis and P. Buehlmann (2012).
Causal Inference Using Graphical Models with the R Package pcalg.
Journal of Statistical Software 47(11) 1–26, <a class="reference external" href="http://www.jstatsoft.org/v47/i11/">http://www.jstatsoft.org/v47/i11/</a></p>
<p>M. Kalisch and P. Buehlmann (2007).
Estimating high-dimensional directed acyclic graphs with the PC-algorithm.
JMLR 8 613-636.</p>
<p>J. Ramsey, J. Zhang and P. Spirtes (2006).
Adjacency-faithfulness and conservative causal inference.
In Proceedings of the 22nd Annual Conference on Uncertainty in Artificial
Intelligence. AUAI Press, Arlington, VA.</p>
<p>P. Spirtes, C. Glymour and R. Scheines (2000).
Causation, Prediction, and Search, 2nd edition. The MIT Press</p>
<p>Strobl, E. V., Zhang, K., &amp; Visweswaran, S. (2017). Approximate
Kernel-based Conditional Independence Tests for Fast Non-Parametric
Causal Discovery. arXiv preprint arXiv:1702.03877.</p>
<p>Imported from the Pcalg package.</p>
<p>The RCIT package has been adapted to fit the <cite>CDT</cite> package, please use the variant available at
<a class="reference external" href="https://github.com/Diviyan-Kalainathan/RCIT">https://github.com/Diviyan-Kalainathan/RCIT</a></p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.graph</span> <span class="kn">import</span> <span class="n">PC</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">PC</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#The predict() method works without a graph, or with a</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#directed or undirected graph provided as an input</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>    <span class="c1">#No graph provided as an argument</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>  <span class="c1">#With an undirected graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span><span class="p">)</span>  <span class="c1">#With a directed graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#To view the graph created, run the below commands:</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<dl class="py method">
<dt id="cdt.causality.graph.PC.create_graph_from_data">
<code class="sig-name descname">create_graph_from_data</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/PC.html#PC.create_graph_from_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.PC.create_graph_from_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Run the PC algorithm.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>data</strong> (<em>pandas.DataFrame</em>) – DataFrame containing the data</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Solution given by PC on the given data.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.graph.PC.orient_directed_graph">
<code class="sig-name descname">orient_directed_graph</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">graph</span></em>, <em class="sig-param"><span class="o">*</span><span class="n">args</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/PC.html#PC.orient_directed_graph"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.PC.orient_directed_graph" title="Permalink to this definition">¶</a></dt>
<dd><p>Run PC on a directed_graph (Only takes account of the skeleton of
the graph).</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> (<em>pandas.DataFrame</em>) – DataFrame containing the data</p></li>
<li><p><strong>graph</strong> (<em>networkx.DiGraph</em>) – Skeleton of the graph to orient</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Solution given by PC on the given skeleton.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>The algorithm is ran on the skeleton of the given graph.</p>
</div>
</dd></dl>

<dl class="py method">
<dt id="cdt.causality.graph.PC.orient_undirected_graph">
<code class="sig-name descname">orient_undirected_graph</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">graph</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/PC.html#PC.orient_undirected_graph"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.PC.orient_undirected_graph" title="Permalink to this definition">¶</a></dt>
<dd><p>Run PC on an undirected graph.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> (<em>pandas.DataFrame</em>) – DataFrame containing the data</p></li>
<li><p><strong>graph</strong> (<em>networkx.Graph</em>) – Skeleton of the graph to orient</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Solution given by PC on the given skeleton.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="sam">
<h3><span class="hidden-section">SAM</span><a class="headerlink" href="#sam" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt id="cdt.causality.graph.SAM">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.graph.</code><code class="sig-name descname">SAM</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">lr</span><span class="o">=</span><span class="default_value">0.01</span></em>, <em class="sig-param"><span class="n">dlr</span><span class="o">=</span><span class="default_value">0.01</span></em>, <em class="sig-param"><span class="n">lambda1</span><span class="o">=</span><span class="default_value">0.01</span></em>, <em class="sig-param"><span class="n">lambda2</span><span class="o">=</span><span class="default_value">1e-05</span></em>, <em class="sig-param"><span class="n">nh</span><span class="o">=</span><span class="default_value">200</span></em>, <em class="sig-param"><span class="n">dnh</span><span class="o">=</span><span class="default_value">200</span></em>, <em class="sig-param"><span class="n">train_epochs</span><span class="o">=</span><span class="default_value">10000</span></em>, <em class="sig-param"><span class="n">test_epochs</span><span class="o">=</span><span class="default_value">1000</span></em>, <em class="sig-param"><span class="n">batchsize</span><span class="o">=</span><span class="default_value">- 1</span></em>, <em class="sig-param"><span class="n">losstype</span><span class="o">=</span><span class="default_value">'fgan'</span></em>, <em class="sig-param"><span class="n">dagstart</span><span class="o">=</span><span class="default_value">0.5</span></em>, <em class="sig-param"><span class="n">dagloss</span><span class="o">=</span><span class="default_value">True</span></em>, <em class="sig-param"><span class="n">dagpenalization</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">dagpenalization_increase</span><span class="o">=</span><span class="default_value">0.001</span></em>, <em class="sig-param"><span class="n">linear</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">hlayers</span><span class="o">=</span><span class="default_value">2</span></em>, <em class="sig-param"><span class="n">njobs</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">gpus</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">verbose</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">nruns</span><span class="o">=</span><span class="default_value">8</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/SAM.html#SAM"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.SAM" title="Permalink to this definition">¶</a></dt>
<dd><p>SAM Algorithm.</p>
<p><strong>Description:</strong> Structural Agnostic Model is an causal discovery algorithm
for DAG recovery leveraging both distributional asymetries and conditional
independencies. the first version of SAM without DAG constraint is available
as <code class="docutils literal notranslate"><span class="pre">SAMv1</span></code>.</p>
<p><strong>Data Type:</strong> Continuous</p>
<p><strong>Assumptions:</strong> The class of generative models is not restricted with a
hard contraint, but with soft constraints parametrized with the <code class="docutils literal notranslate"><span class="pre">lambda1</span></code>
and <code class="docutils literal notranslate"><span class="pre">lambda2</span></code> parameters, with gumbel softmax sampling. This algorithms greatly
benefits from bootstrapped runs (nruns &gt;=8 recommended).
GPUs are recommended but not compulsory. The output is a DAG, but may need a
thresholding as the output is averaged over multiple runs.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>lr</strong> (<em>float</em>) – Learning rate of the generators</p></li>
<li><p><strong>dlr</strong> (<em>float</em>) – Learning rate of the discriminator</p></li>
<li><p><strong>lambda1</strong> (<em>float</em>) – L0 penalization coefficient on the causal filters</p></li>
<li><p><strong>lambda2</strong> (<em>float</em>) – L0 penalization coefficient on the hidden units of the
neural network</p></li>
<li><p><strong>nh</strong> (<em>int</em>) – Number of hidden units in the generators’ hidden layers
(regularized with lambda2)</p></li>
<li><p><strong>dnh</strong> (<em>int</em>) – Number of hidden units in the discriminator’s hidden layer</p></li>
<li><p><strong>train_epochs</strong> (<em>int</em>) – Number of training epochs</p></li>
<li><p><strong>test_epochs</strong> (<em>int</em>) – Number of test epochs (saving and averaging
the causal filters)</p></li>
<li><p><strong>batch_size</strong> (<em>int</em>) – Size of the batches to be fed to the SAM model.
Defaults to full-batch.</p></li>
<li><p><strong>losstype</strong> (<em>str</em>) – type of the loss to be used (either ‘fgan’ (default),
‘gan’ or ‘mse’).</p></li>
<li><p><strong>hlayers</strong> (<em>int</em>) – Defines the number of hidden layers in the discriminator.</p></li>
<li><p><strong>dagloss</strong> (<em>bool</em>) – Activate the DAG with No-TEARS constraint.</p></li>
<li><p><strong>dagstart</strong> (<em>float</em>) – Controls when the DAG constraint is to be introduced
in the training (float ranging from 0 to 1, 0 denotes the start of
the training and 1 the end).</p></li>
<li><p><strong>dagpenalisation</strong> (<em>float</em>) – Initial value of the DAG constraint.</p></li>
<li><p><strong>dagpenalisation_increase</strong> (<em>float</em>) – Increase incrementally at each epoch
the coefficient of the constraint.</p></li>
<li><p><strong>linear</strong> (<em>bool</em>) – If true, all generators are set to be linear generators.</p></li>
<li><p><strong>nruns</strong> (<em>int</em>) – Number of runs to be made for causal estimation.
Recommended: &gt;=8 for optimal performance.</p></li>
<li><p><strong>njobs</strong> (<em>int</em>) – Numbers of jobs to be run in Parallel.
Recommended: 1 if no GPU available, 2*number of GPUs else.</p></li>
<li><p><strong>gpus</strong> (<em>int</em>) – Number of available GPUs for the algorithm.</p></li>
<li><p><strong>verbose</strong> (<em>bool</em>) – verbose mode</p></li>
</ul>
</dd>
</dl>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Ref: Kalainathan, Diviyan &amp; Goudet, Olivier &amp; Guyon, Isabelle &amp;
Lopez-Paz, David &amp; Sebag, Michèle. (2018). Structural Agnostic Modeling:
Adversarial Learning of Causal Graphs.</p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.graph</span> <span class="kn">import</span> <span class="n">SAM</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">SAM</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#The predict() method works without a graph, or with a</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#directed or undirected graph provided as an input</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>    <span class="c1">#No graph provided as an argument</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>  <span class="c1">#With an undirected graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span><span class="p">)</span>  <span class="c1">#With a directed graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#To view the graph created, run the below commands:</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<dl class="py method">
<dt id="cdt.causality.graph.SAM.predict">
<code class="sig-name descname">predict</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">graph</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">return_list_results</span><span class="o">=</span><span class="default_value">False</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/SAM.html#SAM.predict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.SAM.predict" title="Permalink to this definition">¶</a></dt>
<dd><p>Execute SAM on a dataset given a skeleton or not.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> (<em>pandas.DataFrame</em>) – Observational data for estimation of causal relationships by SAM</p></li>
<li><p><strong>skeleton</strong> (<em>numpy.ndarray</em>) – A priori knowledge about the causal relationships as an adjacency matrix.
Can be fed either directed or undirected links.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Graph estimated by SAM, where A[i,j] is the term
of the ith variable for the jth generator.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="samv1">
<h3><span class="hidden-section">SAMv1</span><a class="headerlink" href="#samv1" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt id="cdt.causality.graph.SAMv1">
<em class="property">class </em><code class="sig-prename descclassname">cdt.causality.graph.</code><code class="sig-name descname">SAMv1</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">lr</span><span class="o">=</span><span class="default_value">0.1</span></em>, <em class="sig-param"><span class="n">dlr</span><span class="o">=</span><span class="default_value">0.1</span></em>, <em class="sig-param"><span class="n">l1</span><span class="o">=</span><span class="default_value">0.1</span></em>, <em class="sig-param"><span class="n">nh</span><span class="o">=</span><span class="default_value">50</span></em>, <em class="sig-param"><span class="n">dnh</span><span class="o">=</span><span class="default_value">200</span></em>, <em class="sig-param"><span class="n">train_epochs</span><span class="o">=</span><span class="default_value">1000</span></em>, <em class="sig-param"><span class="n">test_epochs</span><span class="o">=</span><span class="default_value">1000</span></em>, <em class="sig-param"><span class="n">batch_size</span><span class="o">=</span><span class="default_value">- 1</span></em>, <em class="sig-param"><span class="n">nruns</span><span class="o">=</span><span class="default_value">6</span></em>, <em class="sig-param"><span class="n">njobs</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">gpus</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">verbose</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/SAMv1.html#SAMv1"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.SAMv1" title="Permalink to this definition">¶</a></dt>
<dd><p>SAM Algorithm. Implementation of the first version of the SAM algorithm,
available at <a class="reference external" href="https://arxiv.org/abs/1803.04929v1">https://arxiv.org/abs/1803.04929v1</a>.</p>
<p><strong>Description:</strong> Structural Agnostic Model is an fully-differenciable
causal discovery algorithm leveraging both distributional assymetries and
conditional independencies.</p>
<p><strong>Data Type:</strong> Continuous</p>
<p><strong>Assumptions:</strong> The class of generative models is not restricted with a
hard contraint, but with the hyperparameter <code class="docutils literal notranslate"><span class="pre">nh</span></code>. This algorithms greatly
benefits from bootstrapped runs (nruns &gt;=8 recommended).
GPUs are recommended but not compulsory. Output is not a DAG</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>lr</strong> (<em>float</em>) – Learning rate of the generators</p></li>
<li><p><strong>dlr</strong> (<em>float</em>) – Learning rate of the discriminator</p></li>
<li><p><strong>l1</strong> (<em>float</em>) – L1 penalization on the causal filters</p></li>
<li><p><strong>nh</strong> (<em>int</em>) – Number of hidden units in the generators’ hidden layers</p></li>
<li><p><strong>dnh</strong> (<em>int</em>) – Number of hidden units in the discriminator’s hidden layer$</p></li>
<li><p><strong>train_epochs</strong> (<em>int</em>) – Number of training epochs</p></li>
<li><p><strong>test_epochs</strong> (<em>int</em>) – Number of test epochs (saving and averaging the causal filters)</p></li>
<li><p><strong>batch_size</strong> (<em>int</em>) – Size of the batches to be fed to the SAM model.</p></li>
<li><p><strong>nruns</strong> (<em>int</em>) – Number of runs to be made for causal estimation.
Recommended: &gt;=12 for optimal performance.</p></li>
<li><p><strong>njobs</strong> (<em>int</em>) – Numbers of jobs to be run in Parallel.
Recommended: 1 if no GPU available, 2*number of GPUs else.</p></li>
<li><p><strong>gpus</strong> (<em>int</em>) – Number of available GPUs for the algorithm.</p></li>
<li><p><strong>verbose</strong> (<em>bool</em>) – verbose mode</p></li>
</ul>
</dd>
</dl>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Ref: Kalainathan, Diviyan &amp; Goudet, Olivier &amp; Guyon, Isabelle &amp;
Lopez-Paz, David &amp; Sebag, Michèle. (2018). SAM: Structural Agnostic
Model, Causal Discovery and Penalized Adversarial Learning.</p>
</div>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.causality.graph</span> <span class="kn">import</span> <span class="n">SAMv1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cdt.data</span> <span class="kn">import</span> <span class="n">load_dataset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;sachs&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">SAMv1</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#The predict() method works without a graph, or with a</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#directed or undirected graph provided as an input</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>    <span class="c1">#No graph provided as an argument</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">(</span><span class="n">graph</span><span class="p">))</span>  <span class="c1">#With an undirected graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">output</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">graph</span><span class="p">)</span>  <span class="c1">#With a directed graph</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#To view the graph created, run the below commands:</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nx</span><span class="o">.</span><span class="n">draw_networkx</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<dl class="py method">
<dt id="cdt.causality.graph.SAMv1.predict">
<code class="sig-name descname">predict</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">graph</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">return_list_results</span><span class="o">=</span><span class="default_value">False</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cdt/causality/graph/SAMv1.html#SAMv1.predict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cdt.causality.graph.SAMv1.predict" title="Permalink to this definition">¶</a></dt>
<dd><p>Execute SAM on a dataset given a skeleton or not.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>data</strong> (<em>pandas.DataFrame</em>) – Observational data for estimation of causal relationships by SAM</p></li>
<li><p><strong>skeleton</strong> (<em>numpy.ndarray</em>) – A priori knowledge about the causal relationships as an adjacency matrix.
Can be fed either directed or undirected links.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Graph estimated by SAM, where A[i,j] is the term
of the ith variable for the jth generator.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>networkx.DiGraph</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
</div>
</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="independence.html" class="btn btn-neutral float-right" title="cdt.independence" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="tutorial_2.html" class="btn btn-neutral float-left" title="Advanced Tutorial" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        
        &copy; Copyright 2018, Diviyan Kalainathan, Olivier Goudet

    </p>
  </div>
    
    
    
    Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a
    
    <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a>
    
    provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>